Svm
Svm
In the example shown above we can see that there are 4 points which
are nearest to the boundary or are defining boundary, these points are
called “Support Vectors”.
The Non –Separable Case or Nonlinear
data
Simple Example: x = (x1, x2, x3); y = (y1, y2, y3). Then for the function f(x)
= (x1x1, x1x2, x1x3, x2x1, x2x2, x2x3, x3x1, x3x2, x3x3), the kernel is K(x, y
) = (<x, y>)².
Let’s plug in some numbers to make this more intuitive: suppose x = (1, 2, 3);
y = (4, 5, 6). Then:
f(x) = (1, 2, 3, 2, 4, 6, 3, 6, 9)
f(y) = (16, 20, 24, 20, 25, 30, 24, 30, 36)
<f(x), f(y)> = 16 + 40 + 72 + 40 + 100+ 180 + 72 + 180 + 324 = 1024
Now let us use the kernel instead:
K(x, y) = (4 + 10 + 18 ) ^2 = 32² = 1024
Same result, but this calculation is so much easier.
Kernel functions
linear
nonlinear
Polynomial
radial basis function (RBF)
sigmoid
SVM Classifier:
import pandas as pd
from sklearn.datasets import load_iris
iris = load_iris()
iris.feature_names
iris.target_names
df = pd.DataFrame(iris.data,columns=iris.feature_names)
df.head()
df['target'] = iris.target
df.head()
df[df.target==1].head()
df[df.target==2].head()
plt.xlabel('Sepal Length')
plt.ylabel('Sepal Width')
plt.scatter(df0['sepal length (cm)'], df0['sepal width (cm)'],color="green",marker='+')
plt.scatter(df1['sepal length (cm)'], df1['sepal width (cm)'],color="blue",marker='.')
plt.xlabel('Petal Length')
plt.ylabel('Petal Width')
plt.scatter(df0['petal length (cm)'], df0['petal
width(cm)'],color="green",marker='+')
plt.scatter(df1['petal length (cm)'], df1['petal width (cm)'],color="blue",marker='.')
model.score(X_test, y_test)
model.predict([[4.8,3.0,1.5,0.3]])
SVM Regression