版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wnma3mz/article/details/79434125
Day Seven——使用SVM训练数据
第一部分数据`moment.csv“
第一部分——使用SVM训练数据
对应函数programmer_1
步骤:
- 读取数据, 转换矩阵
data.as_matrix()
, 打乱数据shuffle(data)
, 抽取数据集(8:2)。from numpy.random import shuffle
- 转换训练数据和验证数据的格式。
- 用SVC进行训练
svm.SVC()
,from sklearn import svm
- 用
pickle
保存模型pickle.dump
- 使用混淆矩阵评估模型的准确性
metrics.confusion_matrix
,from sklearn import metrics
- 将预测结果保存在新表中
输出如下:
[[39 1 3 0 0]
[ 0 34 0 0 0]
[ 0 0 62 0 0]
[ 0 0 4 14 0]
[ 0 1 0 2 2]]
[[ 8 0 0 0 0]
[ 0 10 0 0 0]
[ 0 0 16 0 0]
[ 0 0 0 6 0]
[ 0 0 0 1 0]]