Python—在0.17中不推荐将1d数组作为数据传递,并且在0.19中会引发ValueError
我正在尝试使用python进行一个小型机器学习示例,其中我绘制了几个坐标,然后预测位置,如下所示:Python—在0.17中不推荐将1d数组作为数据传递,并且在0.19中会引发ValueError,python,machine-learning,scikit-learn,Python,Machine Learning,Scikit Learn,我正在尝试使用python进行一个小型机器学习示例,其中我绘制了几个坐标,然后预测位置,如下所示: import numpy as np import matplotlib.pyplot as plt from matplotlib import style style.use("ggplot") from sklearn import svm x = [1, 5, 2, 8, 3, 9] y = [2, 8, 3, 8, 4, 11] plt.scatter(x,y) plt.show()
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
style.use("ggplot")
from sklearn import svm
x = [1, 5, 2, 8, 3, 9]
y = [2, 8, 3, 8, 4, 11]
plt.scatter(x,y)
plt.show()
X = np.array([[1,2],[5,8],[2,3],[8,8],[3,4],[9,11]])
print(X)
y = [0,1,0,1,0,1]
clf = svm.SVC(kernel='linear', C = 1.0)
clf.fit(X,y)
print(clf.predict([10,10]))
当我运行它时,会出现以下错误:
C:\anaconda\python36\win64\431\lib\site-packages\sklearn\utils\validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)
我是机器学习新手,很难从这里开始学习。您没有收到错误,这是一个警告。警告消息之后仍将打印预测 警告中也列出了解决方案: 使用X重塑数据。如果数据具有 单个特征或X.重塑(1,-1),如果它包含单个样本 按照承诺消除警告:
>> print(clf.predict(np.array([10,10]).reshape(1,-1)))
[1]
此外,从弃用警告来看,代码是否不起作用?警告只是让您知道,1d阵列在未来版本中无法工作。谢谢。现在可以工作是的,它显示在那里,但我试图将数组的形状改为X=X。改形(-1,1),但不起作用。现在,在进行重塑的同时预测其效果。