0
点赞
收藏
分享

微信扫一扫

使用sklearn训练模型出现【DataConversionWarning: A column-vector y was passed when a 1d array was expected】

落拓尘嚣 2023-03-06 阅读 16


问题

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​​


举报

相关推荐

0 条评论