A column-vector y was passed when a 1d array was expected
Change this line:
model = forest.fit(train_fold, train_y)
to:
model = forest.fit(train_fold, train_y.values.ravel())
Explanation:
.values
will give the values in a numpy
array (shape: (n,1))
.ravel
will convert that array shape to (n, ) (i.e. flatten it)
I also encountered this situation when I was trying to train a KNN classifier. but it seems that the warning was gone after I changed:knn.fit(X_train,y_train)
toknn.fit(X_train, np.ravel(y_train,order='C'))
Ahead of this line I used import numpy as np
.
I had the same problem. The problem was that the labels were in a column format while it expected it in a row.
use np.ravel()
knn.score(training_set, np.ravel(training_labels))
Hope this solves it.
use below code:
model = forest.fit(train_fold, train_y.ravel())
if you are still getting slap by error as identical as below ?
Unknown label type: %r" % y
use this code:
y = train_y.ravel()
train_y = np.array(y).astype(int)
model = forest.fit(train_fold, train_y)