我正在尝试将RandomForestRegressor安装到我的训练集中,
rfr.fit(train_X , train_y)
但继续收到以下警告:
/usr/local/lib/python2.7/dist-packages/IPython/kernel/main.py:1: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
if name == ‘main‘:
我正在使用Pandas,因此假设训练集可能需要在numpy数组中,所谓的.values:
train_y = train[label].values
train_X = train[features].values
检查以查看类型和形状:
print type(train_X), train_X.shape
print type(train_y), train_y.shape
返回:
<type 'numpy.ndarray'> (20457, 44)
<type 'numpy.ndarray'> (20457, 1)
不确定接下来该做什么,只发现this answer,但没有多大帮助.
它实际上输出了一个结果,但我不知道它是否是正确的.通过交叉验证,它会一遍又一遍地创建该警告.
最佳答案 警告告诉你到底要做什么,对吧?
问题是什么?如果结果是正确的,尽管有警告?是的,他们是,因为你的意思是使用1d向量y.
如何摆脱警告?如果你的意思是你是1d向量而不是矩阵的列,请使用y.ravel()作为警告说.