本文介绍了在将 Pandas 数据帧列传递给 scikit learn regressor 之前,是否应该以某种方式对其进行转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 Pandas 数据框并将 df[list_of_columns]
作为 X 和 df[[single_column]]
作为 Y
传递给随机森林回归器.
I have a pandas dataframe and passing df[list_of_columns]
as X and df[[single_column]]
as Y
to a Random Forest regressor.
以下警告是什么意思,应该怎么做才能解决?
What does the following warnning mean and what should be done to resolve it?
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(). probas = cfr.fit(trainset_X, trainset_Y).predict(testset_X)
推荐答案
只需检查你的 Y
变量的形状,它应该是一个一维对象,你可能传递了更多的东西(可能是微不足道的)维度.将其重塑为列表/一维数组的形式.
Simply check the shape of your Y
variable, it should be a one-dimensional object, and you are probably passing something with more (possibly trivial) dimensions. Reshape it to the form of list/1d array.
这篇关于在将 Pandas 数据帧列传递给 scikit learn regressor 之前,是否应该以某种方式对其进行转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!