Home > Article > Backend Development > Python implements support vector machine (SVM) classification: detailed explanation of algorithm principles
In machine learning, support vector machine (SVM) is often used for data classification and regression analysis. It is a discriminant algorithm model based on separating hyperplanes. In other words, given labeled training data, the algorithm outputs an optimal hyperplane for classifying new examples.
The support vector machine (SVM) algorithm model represents examples as points in space. After mapping, examples of different categories are divided as much as possible. In addition to performing linear classification, support vector machines (SVMs) can efficiently perform nonlinear classification, implicitly mapping their inputs into a high-dimensional feature space.
Given a set of training examples, each training example is marked with a category according to 2 categories, and then a model is built through the support vector machine (SVM) training algorithm, and new examples are assigned to these 2 categories categories, making it a non-probabilistic binary linear classifier.
Prerequisites: Numpy, Pandas, matplot-lib, scikit-learn
First, create the data set
from sklearn.datasets.samples_generator import make_blobs X,Y=make_blobs(n_samples=500,centers=2, random_state=0,cluster_std=0.40) import matplotlib.pyplot as plt plt.scatter(X[:,0],X[:,1],c=Y,s=50,cmap='spring'); plt.show()
Classification
xfit=np.linspace(-1,3.5) plt.scatter(X[:,0],X[:,1],c=Y,s=50,cmap='spring') for m,b,d in[(1,0.65,0.33),(0.5,1.6,0.55),(-0.2,2.9,0.2)]: yfit=m*xfit+b plt.plot(xfit,yfit,'-k') plt.fill_between(xfit,yfit-d,yfit+d,edgecolor='none', color='#AAAAAA',alpha=0.4) plt.xlim(-1,3.5); plt.show()
The above is the detailed content of Python implements support vector machine (SVM) classification: detailed explanation of algorithm principles. For more information, please follow other related articles on the PHP Chinese website!