问题
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