the Sklean in Python already integrates the SVM algorithm, It includes fit (), predict (), etc., so we can get the results of the classification by simply inputting the training samples and markers, as well as the model parameters.
There are many implementations of this code, and the SVC parameters are described in:
Detailed Address: Http://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html#sklearn.svm.SVC
But for the implementation of LIBSVM in the degree of membership calculation has not found similar explanations and examples, first give the following source code.
Import Numpydata_set = []lab_set = []for k in Range (5): arr = Numpy.random.random ([30000,45]) for i in Numpy.arang E (0,30000): j = i%3 arr[i,k*9+j*3:k*9+j*3+3] = arr[i,k*9+j*3:k*9+j*3+3]+k*0.25 print arr.shape Data _set.extend (arr) Tmp_lab = [k]* (arr.shape[0]) lab_set = lab_set+tmp_labimport sklearnfrom SKLEARN.SVM Import SVCCLF = svc (probability=true) Clf.fit (Data_set, Lab_set) SVC (c=1.0, cache_size=200, Class_weight=none, coef0=0.0, Degree=3, gamma=0.0, kernel= ' RBF ', Max_iter=-1, Probability=true, Random_state=none, Shrinking=true, tol= 0.001, verbose=false) Pre_lab = clf.predict (data_set) PRE_SCR = Clf.score (data_set,lab_set) print (Pre_lab.shape)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Python sklearn Calculation of SVM membership