Value Error:Wrong number of items passed 2, placement implies 1

浪尽此生 提交于 2020-01-05 07:06:13

问题


This code works fine...

forest1 = RandomForestClassifier()
forest1.fit(train[['Random Forest Score','lr','neural']],train['target'])

But when I try to predict ,

test['target'] = forest1.predict_proba(test[['Random Forest Score','lr','neural']])

It shows an error..

ValueError: Wrong number of items passed 2, placement implies 1


回答1:


forest1.predict_proba(...) predicts class probabilities for X.

It returns an array of shape = [n_samples, n_classes], or a list of n_outputs such arrays if n_outputs > 1. The class probabilities of the input samples. The order of the classes corresponds to that in the attribute classes_.

test['target'] expects a vector (1D array)

Try to use predict() instead of predict_proba:

test['target'] = forest1.predict(test[['Random Forest', 'Score','lr','neural']])


来源:https://stackoverflow.com/questions/46541314/value-errorwrong-number-of-items-passed-2-placement-implies-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!