本文主要是介绍使用sklearn训练模型出现【DataConversionWarning: A column-vector y was passed when a 1d array was expected】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题
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().clf.fit(x,y)
- 貌似是因为fit()第二个参数(也就是label)必须是(n.)格式的,而传入的是(n,1)格式的,所以我们需要将他转换。
解决
- 使用ravel(y)函数
clf.fit(x,np.ravel(y))
- 该函数的意义在于展平这个矩阵。
Reference
A column-vector y was passed when a 1d array was expected
这篇关于使用sklearn训练模型出现【DataConversionWarning: A column-vector y was passed when a 1d array was expected】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!