这段代码运行正常…
forest1 = RandomForestClassifier()forest1.fit(train[['Random Forest Score','lr','neural']],train['target'])
但是当我尝试预测时,
test['target'] = forest1.predict_proba(test[['Random Forest Score','lr','neural']])
它显示了一个错误…
值错误:传递的项目数量错误,传递了2个,位置暗示应为1
回答:
forest1.predict_proba(…) 预测类别的概率。
它返回一个形状为 [n_samples, n_classes]
的数组,或者如果 n_outputs > 1,则返回一个包含 n_outputs 个此类数组的列表。输入样本的类别概率。类别的顺序对应于属性 classes_ 中的顺序。
test['target']
期望一个向量(一维数组)
尝试使用 predict()
代替 predict_proba
:
test['target'] = forest1.predict(test[['Random Forest', 'Score','lr','neural']])