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.