簡單的svm例子

數據來源:https://github.com/oumiga1314/Coursera-ML-AndrewNg-Notes/blob/master/code/ex6-SVM/data/ex6data1.matgit

import pandas as pd import numpy as np import scipy.io as sio import seaborn as sns import sklearn.svm as skgithub

path = '../svm/ex6data1.mat' mat = sio.loadmat(path) data = pd.DataFrame(mat.get('X'),columns=['X1','X2']) data['y'] = mat.get('y')ide

svm_line = sk.LinearSVC(C=1,loss='hinge') svm_line.fit(data[['X1','X2']],data['y']) sco = svm_line.score(data[['X1','X2']],data['y']) data['SVM1 Confidence'] =svm_line.decision_function(data[['X1', 'X2']]) ax.scatter(data['X1'], data['X2'], s=50, c=data['SVM1 Confidence'], cmap='RdBu') ax.set_title('SVM (C=1) Decision Confidence') plt.show()code

相關文章
相關標籤/搜索