机器学习:基础知识折旧警告
Machine Learning: Basics DepreciationWarning
我是运行一个基本的机器学习教程代码片段(在教学人员的计算机上正确编译),我似乎找不到问题所在。我明白问题是 'answered',但我似乎无法理解答案。
DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise 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)
[0]
显然我只是使用 X.reshape(-1, 1) 或 X.reshape(1, -1),但我不确定它们在一般情况下究竟如何工作,或者如果它们应该放在我 plot/for 数据之前或之后。
这是我的源代码。非常感谢任何帮助:-)
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
style.use("ggplot")
from sklearn import svm
x = [1, 5, 1.5, 8, 1, 9]
y = [2, 8, 1.8, 8, 0.6, 11]
plt.scatter(x,y)
plt.show()
X = np.array([[1,2],
[5,8],
[1.5,1.8],
[8,8],
[1,0.6],
[9,11]])
y = [0,1,0,1,0,1]
clf = svm.SVC(kernel='linear', C = 1.0)
clf.fit(X,y)
print(clf.predict([0.58,0.76]))
由于您的数据具有不止一个特征并且包含多个样本,所以您没问题。这只是一个警告,不应干扰算法的行为。
我是运行一个基本的机器学习教程代码片段(在教学人员的计算机上正确编译),我似乎找不到问题所在。我明白问题是 'answered',但我似乎无法理解答案。
DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise 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) [0]
显然我只是使用 X.reshape(-1, 1) 或 X.reshape(1, -1),但我不确定它们在一般情况下究竟如何工作,或者如果它们应该放在我 plot/for 数据之前或之后。
这是我的源代码。非常感谢任何帮助:-)
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
style.use("ggplot")
from sklearn import svm
x = [1, 5, 1.5, 8, 1, 9]
y = [2, 8, 1.8, 8, 0.6, 11]
plt.scatter(x,y)
plt.show()
X = np.array([[1,2],
[5,8],
[1.5,1.8],
[8,8],
[1,0.6],
[9,11]])
y = [0,1,0,1,0,1]
clf = svm.SVC(kernel='linear', C = 1.0)
clf.fit(X,y)
print(clf.predict([0.58,0.76]))
由于您的数据具有不止一个特征并且包含多个样本,所以您没问题。这只是一个警告,不应干扰算法的行为。