Lesson 30
Support Vector Machine
Draw the class boundary with the widest margin, and let a kernel bend that boundary when a straight cut is not enough. One example is on this page.
Intermediate12 min
What You Will Learn
- Idea
- Example
- When to use it
Idea
A support vector machine looks for the gap between classes and places the boundary in the middle of that gap. Only the points on the edge, the support vectors, define it. A kernel compares points in a richer space so the boundary can curve.
Example
import numpy as np
from sklearn.svm import SVC
X = np.array([[1, 1], [2, 1], [1, 2], [6, 6], [7, 6], [6, 7]], dtype=float)
y = np.array([0, 0, 0, 1, 1, 1])
label = SVC(kernel="linear").fit(X, y).predict([[4, 4]])[0]
print(f"label: {int(label)}")Output:
label: 1When to use it
- Use it when the classes are separable by a gap and the table is moderate in size.
- Scale the inputs. The margin is a distance.
- A linear kernel is the place to start. RBF is the next step when the gap is curved.
The theory lesson Support Vector Machines covers the margin.
Loading playground…