使用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

你可能感兴趣的:(机器学习)