SVM Classifier
π― Purpose¶
This QuickRef outlines how to use Support Vector Machine (SVM) classifiers. It covers decision boundaries, kernels, hyperparameters, and practical usage for binary and multiclass classification.
π¦ 1. When to Use¶
Condition | Use SVM? |
---|---|
Linear boundary works well | β Yes (linear SVM) |
You need clear margin between classes | β Yes |
Nonlinear boundary needed | β Yes (use kernels) |
Huge dataset or sparse input | β Can be slow; use SGD or trees |
βοΈ 2. Core Logic¶
- Finds hyperplane that maximally separates classes
- Only support vectors (borderline points) influence boundary
- Uses kernel trick to map inputs to higher dimensions
π οΈ 3. Fitting in sklearn¶
from sklearn.svm import SVC
model = SVC(kernel='rbf', C=1.0, probability=True)
model.fit(X_train, y_train)
βοΈ Use probability=True
for predict_proba()
(not on by default)
π§ 4. Key Hyperparameters¶
Param | Description |
---|---|
C |
Regularization strength (low = wider margin, more misclassifications) |
kernel |
Mapping function: 'linear' , 'rbf' , 'poly' , 'sigmoid' |
gamma |
Controls curvature of decision boundary (higher = more flexible) |
probability |
Enables predict_proba() (slower training) |
π 5. Common Kernels¶
Kernel | Use When... |
---|---|
linear |
Data is roughly linearly separable |
rbf (default) |
General-purpose nonlinear mapping |
poly |
Polynomial relationships exist |
sigmoid |
Rarely used (like a shallow neural net) |
π 6. Evaluation Tips¶
- Use
accuracy
,precision
,recall
,AUC
- Use
GridSearchCV
to tuneC
andgamma
- Normalize or standardize features before fitting
β Checklist¶
- [ ] Target is binary or multiclass
- [ ] Feature scaling applied
- [ ] Kernel chosen based on linearity needs
- [ ]
C
andgamma
tuned via cross-validation - [ ] If
predict_proba
needed, enable inSVC
π‘ Tip¶
βSupport Vector Machines donβt memorize your data β they focus only on what matters: the boundary.β