我正在尝试运行以下标签:
def test_ensemble_labels(train_data, y, test_data, vector_names, NNeighbours, lower, upper):
y_pred = []
for j in range(len(vector_names)):
y_pred.append(frnn_owa_method(train_data, y, test_data, vector_names[j], NNeighbours[j], lower, upper)[1])
# Use voting function to obtain the ensembled label - we used mean
y_pred_res = np.mean(y_pred, axis=0)
return y_pred_res
predicted_labels = test_ensemble_labels(data, data['Label'], test_data, ["Vector_d2v"], [19], additive(), additive())
但我得到一个信息:
/content/frnn_owa_eval.py:33: RuntimeWarning: invalid value encountered in true_divide
distances = 1 - 0.5 * X @ self.X_T / np.linalg.norm(X, axis=1)[:, None] / self.X_T_norm
这是一个包含距离的函数:
def _query(self, X, m_int: int):
distances = 1 - 0.5 * X @ self.X_T / np.linalg.norm(X, axis=1)[:, None] / self.X_T_norm
return least_indices_and_values(distances, m_int, axis=-1)
1条答案
按热度按时间exdqitrt1#
您的代码正在尝试执行经典的“除以零”或“除以nan”。预处理数据集/变量,以便事先检查这些条件。
如果您不想这样做,可以使用以下方法绕过: