This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://scikit-learn.org/stable/modules/svm.html#classification | |
#SVM | |
#Classification, Outlier detection | |
#Useful for high dimensional spaces | |
#two class classification | |
from sklearn import svm | |
x = [[0,0],[1,1],[3,3],[5,5],[2,3]] | |
y = [0,1,2,1,1] | |
svmmodel = svm.SVC() | |
svmmodel.fit(x,y) | |
#property attributes of SVM | |
print(svmmodel.support_vectors_) | |
#indexes of support vectors | |
print(svmmodel.support_) | |
#number of support vectors for each class | |
print(svmmodel.n_support_) | |
#multi-class classification | |
#SVC, NuSVC and LinearSVC are classes capable of performing multi-class classification on a dataset. | |
#For unbalanced problems certain individual samples keywords class_weight and sample_weight can be used. | |
svmweightmodel = svm.SVC(class_weight={0:0.8,1:0.1,2:0.1}) | |
svmweightmodel.fit(x,y) | |
print('Default Prediction') | |
print(svmmodel.predict([[1.,1.]])) | |
print('Weight Prediction') | |
print(svmweightmodel.predict([[1.,1.]])) | |
#linear svc | |
#LinearSVC implements “one-vs-the-rest” multi-class strategy | |
linearsvcmodel = svm.LinearSVC() | |
linearsvcmodel.fit(x,y) | |
print('linearsvcmodel Prediction') | |
print(linearsvcmodel.predict([[1.,1.]])) | |
No comments:
Post a Comment