runtimewarning:true_divide distance=1-0.5*x@self.x_t/np.linalg.norm(x,axis=1)[:,none]/self.x_t_norm中遇到无效值

ukxgm1gy  于 2021-09-08  发布在  Java
关注(0)|答案(1)|浏览(274)

我正在尝试运行以下标签:

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)
exdqitrt

exdqitrt1#

您的代码正在尝试执行经典的“除以零”或“除以nan”。预处理数据集/变量,以便事先检查这些条件。
如果您不想这样做,可以使用以下方法绕过:

import numpy as np
np.seterr(divide='ignore', invalid='ignore')

相关问题