Support Vector Machines are powerful supervised learning models used for classification, regression, and outlier detection.
SVC / SVR:
kernel='rbf' (default), 'poly', or 'linear'.LinearSVC / LinearSVR:
SVC(kernel='linear') for large datasets.OneClassSVM:
C: Regularization parameter.
C: Smaller margin, fits training data better (risk of overfitting).C: Larger margin, simplifies the decision boundary (risk of underfitting).gamma: Defines how far the influence of a single training example reaches.
gamma: Local influence (complex boundaries).gamma: Global influence (simpler boundaries).from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV
# 1. Tuning C and Gamma
param_grid = {
'C': [0.1, 1, 10, 100],
'gamma': [1, 0.1, 0.01, 0.001],
'kernel': ['rbf']
}
grid = GridSearchCV(SVC(), param_grid, refit=True, verbose=2)
grid.fit(X_train, y_train)
# 2. Linear SVC for large-scale data
from sklearn.svm import LinearSVC
l_svc = LinearSVC(C=1.0, max_iter=10000)
l_svc.fit(X_train, y_train)
Credits: This cheatsheet is based on the scikit-learn documentation and examples, which are licensed under the BSD 3-Clause License. Copyright (c) 2007 - 2026 The scikit-learn developers. All rights reserved.