我正在尝试通过递归特征消除来计算机器学习模型的 log_loss,并且当我尝试运行 sklearns predict_proba 函数时发生值错误
我目前试图通过 RFE 删除修改我的数据集的代码。当我这样做时,不会发生形状改变,同样的错误仍然会发生。测试数据的形状从 (44,2048) 开始,测试标签从 (44,) 开始,改装后变为:测试数据形状变为 (44,57) 测试标签不受影响
我真的不知道接下来要尝试什么,任何建议都会有所帮助。我不明白 (4,) 是从哪里来的,因为它试图将我的数据塑造成它
def get_log_loss(self, test_data, test_labels, rfe):
rfe.fit(test_data, test_labels)
test_data = rfe.transform(test_data)
test_probs = self._model.predict_proba(test_data)
score = log_loss(test_labels, test_probs)
return score
错误:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\helpers\pydev\pydevd.py", line 2060, in <module>
main()
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\helpers\pydev\pydevd.py", line 2054, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\helpers\pydev\pydevd.py", line 1405, in run
return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\helpers\pydev\pydevd.py", line 1412, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/myname/PycharmProjects/MQP/mainv1.py", line 376, in <module>
test_model(test_batch, test_labels, j, l)
File "C:/Users/myname/PycharmProjects/MQP/mainv1.py", line 190, in test_model
logloss = model_obj.get_log_loss(a_test_batch, a_test_labels, rfe)
File "C:\Users\myname\PycharmProjects\MQP\trainData.py", line 59, in get_log_loss
test_probs = self._model.predict_proba(test_data)
File "C:\Users\myname\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\naive_bayes.py", line 104, in predict_proba
return np.exp(self.predict_log_proba(X))
File "C:\Users\myname\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\naive_bayes.py", line 84, in predict_log_proba
jll = self._joint_log_likelihood(X)
File "C:\Users\myname\AppData\Local\Continuum\anaconda3\lib\site-packages\sklearn\naive_bayes.py", line 437, in _joint_log_likelihood
n_ij -= 0.5 * np.sum(((X - self.theta_[i, :]) ** 2) /
ValueError: operands could not be broadcast together with shapes (44,57) (4,)