SVC function(sklearn), Support vector machine



Python
library
pip

MeCab

numpy
digitize

mgrid

pad

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

scipy
interpolate
tkinter
postscript

image display

frame, grid

other
linear interpolation

OpenAI gym
CartPole-v0


Release date:2022/7/24         

In Japanese


■Description of SVC function

We perform classification by support vector machine (SVM). Click here to install various libraries such as scikit-learn.

■Specific example of SVC function

In the graph below, We classify test data to which training data label it belongs to.



The python program is as follows.

from sklearn import svm
import numpy as np
import matplotlib.pyplot as plt

X = np.array([[5,10],[8,50],[10,20]])  # training data
Y = np.array([1, 2, 3])    # training data label
t = np.array([[9,20]])    # test data

clf = svm.SVC(kernel='rbf', gamma =0.0001, C=1000)    # SVM definition
clf.fit(X, Y)    # Fitting to training data
print(clf.predict(t))    # Classify test data

plt.plot([5,8,10],[10,50,20],'o')    # training data plot
plt.plot([9],[20],'^')    # test data plot
plt.grid(True)
plt.show()


The result returned a value of 3. It's certainly close to 3 in the training data, so I think the results are reasonable. The SVC setting parameters are as follows.

<kernel>

Set the kernel function. Mainly as follows.

 linear
 poly
 rbf (Radial basis function, Here is the Gauss kernel)
 sigmoid

<gamma>

Determine the degree of spread of the distribution centered on the training data. The smaller the value, the looser the distribution and the less sensitive to the training data. If the value is large, the distribution becomes sharp and it becomes easy to fit the training data, but on the other hand, it becomes easy to overfit.

<C>

Cost parameter. The smaller the value, the more error is tolerated. The larger the value, the less tolerant of errors and the easier it is to overfit.









List of related articles



Python
library
pip

MeCab

numpy
digitize

mgrid

pad

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

scipy
interpolate
tkinter
postscript

image display

frame, grid

other
linear interpolation

OpenAI gym
CartPole-v0