Support Vector Machines Cheat Sheet
A cheat sheet for Support Vector Machines covering kernels, margin maximization, the C and gamma hyperparameters, and scikit-learn usage.
2 PagesIntermediateFeb 25, 2026
Classifier with scikit-learn
Fit a scaled RBF-kernel SVM.
python
from sklearn.svm import SVCfrom sklearn.preprocessing import StandardScalerfrom sklearn.pipeline import make_pipelineclf = make_pipeline( StandardScaler(), SVC(kernel='rbf', C=1.0, gamma='scale', probability=True))clf.fit(X_train, y_train)print('Accuracy:', clf.score(X_test, y_test))
Kernel Comparison
Common kernel choices for SVC.
python
from sklearn.svm import SVClinear_svm = SVC(kernel='linear', C=1.0)poly_svm = SVC(kernel='poly', degree=3, C=1.0)rbf_svm = SVC(kernel='rbf', gamma=0.1, C=1.0) # default kernelsigmoid_svm = SVC(kernel='sigmoid', C=1.0)
Hyperparameter Grid Search
Tune C and gamma with cross-validation.
python
from sklearn.model_selection import GridSearchCVparam_grid = {'C': [0.1, 1, 10, 100], 'gamma': [1, 0.1, 0.01, 0.001]}grid = GridSearchCV(SVC(kernel='rbf'), param_grid, cv=5, scoring='f1')grid.fit(X_train, y_train)print(grid.best_params_)
Key Concepts
Core theory behind SVMs.
- Support vectors- Training points closest to the decision boundary; they alone define the margin
- Margin- Distance between the decision boundary and the nearest points; SVM maximizes this distance
- Kernel trick- Implicitly maps data into a higher-dimensional space to find a linear separator, without computing the mapping explicitly
- C (regularization)- Trades off margin width against classification error; a large C allows less margin violation
- gamma (RBF kernel)- Controls the influence radius of a single training point; high gamma risks overfitting
- Feature scaling- SVMs rely on distances, so features should always be standardized before fitting
Pro Tip
Always scale features before training an SVM — because the algorithm depends on distances and dot products, an unscaled feature with a large numeric range will dominate the margin calculation and quietly degrade model performance.
Was this cheat sheet helpful?
Explore Topics
#SupportVectorMachines#SupportVectorMachinesCheatSheet#DataScience#Intermediate#ClassifierWithScikitLearn#KernelComparison#HyperparameterGridSearch#KeyConcepts#MachineLearning#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance