Python implements support vector machine (SVM) classification: detailed explanation of algorithm principles

WBOY
Release: 2024-01-24 09:33:05
forward
1016 people have browsed it

支持向量机(SVM)算法原理 Python实现支持向量机(SVM)分类

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.

What does a support vector machine do?

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.

Python implements support vector machine (SVM) classification

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()
Copy after login

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()
Copy after login

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!

source:163.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!