One - One Code All

Blog Content

sklearn学习之svm

机器学习   2013-05-13 22:37:38

经过前面的基础学习,就直接上代码吧。

from sklearn import svm
import numpy as np

x = [[0, 0], [1, 1], [2, 3]] # 训练样本
y = [0, 0, 1]  #标签
clf = svm.SVC(kernel= 'linear')
clf.fit(x, y)  # 训练svc模型


print(clf)
print('支持向量', clf.support_vectors_) #支持向量
print('下标', clf.support_) #支持向量下标
print('svm个数',clf.n_support_) #每一类中有几个支持向量
z = [0, 1]
z = np.array(z).reshape((1, -1))
print(clf.predict([[2, 3]])) #测试数据
print(clf.predict(z)) #测试数据



上一篇:sklearn入门之knn算法
下一篇:sklearn加载自主数据

The minute you think of giving up, think of the reason why you held on so long.