经过前面的基础学习,就直接上代码吧。
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)) #测试数据