gpt4 book ai didi

python - 将列表转换为 svm 输入

转载 作者:行者123 更新时间:2023-11-30 22:48:24 25 4
gpt4 key购买 nike

我正在使用 python 和 scikit learn 实现 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为原始数据列表。

关于python - 将列表转换为 svm 输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40182051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com