1.支持向量机推导
2.案例
import numpy as np import sklearn.model_selection as ms import sklearn.svm as svm import sklearn.metrics as sm import matplotlib.pyplot as mp import matplotlib as mpl #绘制分类图的过程 #1.求出所有的格点,并绘出预测结果。 2.画出测试数据的散点图, if __name__ == '__main__': data=np.loadtxt(open("/home/python/Desktop/test.csv"),dtype=float,delimiter=",",) train_x,test_x,train_y,test_y=ms.train_test_split(data[:,:-1],data[:,-1],test_size=0.25) svm1=svm.SVC(kernel="linear",C=100,class_weight="balanced") svm1.fit(train_x,train_y) result=svm1.predict(test_x) s=sm.classification_report(test_y,result)#分类准确率相关数据 #绘制分类图 x1_min,x1_max=data[:,0].min()-1,data[:,0].max()+1 x2_min, x2_max = data[:, 1].min()-1, data[:, 1].max() + 1 x1,x2=np.meshgrid(np.linspace(x1_min,x1_max,num=100),np.linspace(x2_min, x2_max, num=100)) b=np.column_stack((x1.flatten(),x2.flatten())) result=svm1.predict(b) mp.pcolormesh(x1,x2,result.reshape(x1.shape),cmap="jet") mp.scatter(test_x[:,0],test_x[:,1],s=30,c=test_y,cmap="gray",label="sample") mp.show()
2.松弛因子
3.低维高维转换内积
4.核函数