DataConversion Support for RandomForestRegressor in Scikit

I am trying to put RandomForestRegressor in my training set,

rfr.fit(train_X , train_y)

but keep getting the following warning:

/usr/local/lib/python2.7/dist-packages/IPython/kernel/ main .py: 1: DataConversionWarning: column vector y was passed while waiting for a 1d array.Change the form y to (n_samples), for example using ravel (). if name == ' main ':

I use Pandas, and therefore suggested that the training set might need to be in numpy arrays, so-called .values:

train_y = train[label].values
train_X = train[features].values

Type and form check:

print type(train_X), train_X.shape
print type(train_y), train_y.shape

Returns:

<type 'numpy.ndarray'> (20457, 44)  
<type 'numpy.ndarray'> (20457, 1)

Not sure what to do next, just found this answer , but it did not help.

, , . .

+4
3

, , ?   ? , ? , , 1- y.

? , y 1d-, , y.ravel(), .

+2

y.shape=y.shape[0], y.shape (20457,), (20457,1)

0

As the warning says, we want to resize from (N, 1) to (N,). we can use the numpy ravel function.

Use np.ravel (train_y) instead of train_y.

You can also try train_y.reshape ((- 1,)).

0
source

All Articles