ERROR: test_pt_common_predict (__main__.TestCommonExecutor) ---------------------------------------------------------------------- Traceback (most recent call last): File "d_warehouse/vot/z_test/z_model/cv/pt_common.py", line 54, in test_pt_common_predict Mnist(self.data_dir, man="gcgS467j").b("0001").run() File "/django_scrapy/d_warehouse/vot/base/base.py", line 357, in run return self.do_run() File "/django_scrapy/d_warehouse/vot/data/dataset/cv/mnist.py", line 34, in do_run train_df = self.sqlc.createDataFrame(train_data_list) File "/usr/local/lib/python3.8/dist-packages/pyspark/sql/context.py", line 473, in createDataFrame return self.sparkSession.createDataFrame( # type: ignore[call-overload] File "/usr/local/lib/python3.8/dist-packages/pyspark/sql/session.py", line 1222, in createDataFrame self._jvm.SparkSession.setActiveSession(self._jsparkSession) File "/usr/local/lib/python3.8/dist-packages/py4j/java_gateway.py", line 1712, in __getattr__ answer = self._gateway_client.send_command( File "/usr/local/lib/python3.8/dist-packages/py4j/java_gateway.py", line 1036, in send_command connection = self._get_connection() File "/usr/local/lib/python3.8/dist-packages/py4j/clientserver.py", line 284, in _get_connection connection = self._create_new_connection() File "/usr/local/lib/python3.8/dist-packages/py4j/clientserver.py", line 291, in _create_new_connection connection.connect_to_java_server() File "/usr/local/lib/python3.8/dist-packages/py4j/clientserver.py", line 438, in connect_to_java_server self.socket.connect((self.java_address, self.java_port)) ConnectionRefusedError: [Errno 111] Connection refused
时间: 2023-12-14 09:02:37 浏览: 211
这个错误表明你的代码尝试连接到一个 Java 服务器,但连接被拒绝了。可能有几个原因导致这个问题:
1. Java 服务器没有正确启动或正在运行。请确保你的 Java 服务器正在运行,并且监听的端口没有被其他进程占用。
2. 防火墙或网络配置问题。防火墙或网络配置可能会阻止你的代码与 Java 服务器建立连接。请检查防火墙设置并确保网络配置正确。
3. IP 地址或端口号错误。请确保你提供给代码的 Java 服务器的 IP 地址和端口号是正确的。
请仔细检查上述原因,并根据实际情况进行相应的调整。如果问题仍然存在,请提供更多的代码和错误上下文,以便进一步帮助你解决问题。
相关问题
AttributeError Traceback (most recent call last) Cell In[21], line 62 60 softmax_probs = softmax_model.predict_proba(X_test_scaled) 61 mlp_probs = mlp_model.predict_proba(X_test_scaled) ---> 62 svm_probs = svm_model.predict_proba(X_test_scaled)[:, 1] 64 softmax_fpr, softmax_tpr, _ = roc_curve(y_test, softmax_probs[:, 1], pos_label=2) 65 mlp_fpr, mlp_tpr, _ = roc_curve(y_test, mlp_probs[:, 1], pos_label=2) File D:\ANACONDA\lib\site-packages\sklearn\utils\_available_if.py:32, in _AvailableIfDescriptor.__get__(self, obj, owner) 26 attr_err = AttributeError( 27 f"This {repr(owner.__name__)} has no attribute {repr(self.attribute_name)}" 28 ) 29 if obj is not None: 30 # delegate only on instances, not the classes. 31 # this is to allow access to the docstrings. ---> 32 if not self.check(obj): 33 raise attr_err 34 out = MethodType(self.fn, obj) File D:\ANACONDA\lib\site-packages\sklearn\svm\_base.py:829, in BaseSVC._check_proba(self) 827 def _check_proba(self): 828 if not self.probability: --> 829 raise AttributeError( 830 "predict_proba is not available when probability=False" 831 ) 832 if self._impl not in ("c_svc", "nu_svc"): 833 raise AttributeError("predict_proba only implemented for SVC and NuSVC") AttributeError: predict_proba is not available when probability=False
这个错误是由于支持向量机模型(SVC)的probability参数设置为False时,不支持使用predict_proba方法来获取样本属于各个类别的概率导致的。
解决这个问题有两种方法:
1. 将SVC模型的probability参数设置为True。修改代码如下:
```python
svm_model = SVC(kernel='rbf', C=1.0, probability=True)
```
使用上述代码替换原代码中的`svm_model = SVC(kernel='rbf', C=1.0)`,然后再次运行程序,即可解决该错误。
2. 使用decision_function方法来获取样本距离分类超平面的距离,并手动将其转换为概率值。修改代码如下:
```python
svm_distances = svm_model.decision_function(X_test_scaled)
svm_probs = (svm_distances - svm_distances.min()) / (svm_distances.max() - svm_distances.min())
```
使用上述代码替换原代码中的`svm_probs = svm_model.predict_proba(X_test_scaled)[:, 1]`,然后再次运行程序,即可解决该错误。
希望这个解决方案能帮助到你!如果还有其他问题,请随时提问。
def build_sequences(text, window_size): #text:list of capacity x, y = [],[] for i in range(len(text) - window_size): sequence = text[i:i+window_size] target = text[i+1:i+1+window_size] x.append(sequence) y.append(target) return np.array(x), np.array(y) # 留一评估:一组数据为测试集,其他所有数据全部拿来训练 def get_train_test(data_dict, name, window_size=8): data_sequence=data_dict[name][1] train_data, test_data = data_sequence[:window_size+1], data_sequence[window_size+1:] train_x, train_y = build_sequences(text=train_data, window_size=window_size) for k, v in data_dict.items(): if k != name: data_x, data_y = build_sequences(text=v[1], window_size=window_size) train_x, train_y = np.r_[train_x, data_x], np.r_[train_y, data_y] return train_x, train_y, list(train_data), list(test_data) def relative_error(y_test, y_predict, threshold): true_re, pred_re = len(y_test), 0 for i in range(len(y_test)-1): if y_test[i] <= threshold >= y_test[i+1]: true_re = i - 1 break for i in range(len(y_predict)-1): if y_predict[i] <= threshold: pred_re = i - 1 break return abs(true_re - pred_re)/true_re def evaluation(y_test, y_predict): mae = mean_absolute_error(y_test, y_predict) mse = mean_squared_error(y_test, y_predict) rmse = sqrt(mean_squared_error(y_test, y_predict)) return mae, rmse def setup_seed(seed): np.random.seed(seed) # Numpy module. random.seed(seed) # Python random module. os.environ['PYTHONHASHSEED'] = str(seed) # 为了禁止hash随机化,使得实验可复现。 torch.manual_seed(seed) # 为CPU设置随机种子 if torch.cuda.is_available(): torch.cuda.manual_seed(seed) # 为当前GPU设置随机种子 torch.cuda.manual_seed_all(seed) # if you are using multi-GPU,为所有GPU设置随机种子 torch.backends.cudnn.benchmark = False torch.backends.cudnn.deterministic = True
这段代码主要是用来进行数据预处理和模型评估的。其中,`build_sequences`函数用来将数据转化为序列数据,`get_train_test`函数用来获取训练集和测试集,`relative_error`函数用来计算相对误差,`evaluation`函数用来计算模型的MAE、MSE和RMSE指标。另外,`setup_seed`函数用来设置随机种子,以保证实验的可复现性。整个代码涉及到了numpy、random、os和torch等库的使用,可以用来进行深度学习相关的实验和研究。
阅读全文