我正在使用python和scikit学习实现svm模型。我已经选择并转换了我的特征,并将它们合并到一个列表中,如下所示:
[[17, 14, 14, 7, 14, 14, 14, 7, 14, 14, 1],
[14, 14, 7, 14, 14, 14, 7, 14, 14, 7, 1],
[14, 7, 14, 14, 14, 7, 14, 14, 7, 14, 1],
[7, 14, 14, 14, 7, 14, 14, 7, 14, 7, 1],
[14, 14, 14, 7, 14, 14, 7, 14, 7, 14, 1],
[14, 14, 7, 14, 14, 7, 14, 7, 14, 7, 1],
[14, 7, 14, 14, 7, 14, 7, 14, 7, 13, 1],
[7, 14, 14, 7, 14, 7, 14, 7, 13, 7, 1],
[14, 14, 7, 14, 7, 14, 7, 13, 7, 14, 1],
[14, 7, 14, 7, 14, 7, 13, 7, 14, 10, 1],
[7, 14, 7, 14, 7, 13, 7, 14, 10, 4, 1],
[14, 7, 14, 7, 13, 7, 14, 10, 4, 13, 1],
[7, 14, 7, 13, 7, 14, 10, 4, 13, 13, 1],
[14, 7, 13, 7, 14, 10, 4, 13, 13, 7, 1],
[7, 13, 7, 14, 10, 4, 13, 13, 7, 13, 1],
[13, 7, 14, 10, 4, 13, 13, 7, 13, 3, 1],
[7, 14, 10, 4, 13, 13, 7, 13, 3, 13, 1],
[14, 10, 4, 13, 13, 7, 13, 3, 13, 13, 1],
[10, 4, 13, 13, 7, 13, 3, 13, 13, 3, 1],
[4, 13, 13, 7, 13, 3, 13, 13, 3, 13, 0],
[13, 13, 7, 13, 3, 13, 13, 3, 13, 13, 0],
[13, 7, 13, 3, 13, 13, 3, 13, 13, 14, 0]]
每个元组中的最后一个数字是标签。我试图找到一种方法来创建一个数据集,可以分离数据和目标,以建立一个模型。我在文档中找不到类似的东西。把它转回Dataframe会更容易吗?
谢谢!
你的意思是把特征和标签分开吗?如果是,可以使用numpy.
from sklearn import svm
import numpy as np
data = np.asarray(A)
X = data[:,:-1]
y = data[:,-1]
clf = svm.SVC()
clf.fit(X, y)
A为原始数据列表。