Explain SVMs and kernels from an interviewer's point of view
Written by the mlprep team · Updated
Explain support vector machines. What is the margin, what do kernels do, and when would you still use an SVM?
Maximum-margin idea#
An SVM finds a decision boundary that separates classes while maximizing the margin: the distance between the boundary and the closest training points. The closest points are the support vectors. They determine the boundary.
Large margin is a form of regularization. Many boundaries may classify the training set correctly, but the maximum-margin boundary often generalizes better.
Soft margin#
Real data is rarely perfectly separable. Soft-margin SVMs allow violations using slack variables. The C parameter controls the tradeoff:
- large
C: penalize mistakes heavily, lower bias, higher overfitting risk - small
C: allow wider margin and more violations, higher bias, more regularization
Kernels#
Kernels let SVMs learn nonlinear boundaries without explicitly constructing high-dimensional features. The model only needs dot products between examples. A kernel computes:
K(x_i, x_j) = phi(x_i) dot phi(x_j)
Common kernels:
- Linear: good for high-dimensional sparse features.
- RBF: flexible nonlinear boundary, sensitive to gamma.
- Polynomial: interactions up to a chosen degree.
When SVMs are useful#
SVMs can still be strong for small-to-medium datasets, high-dimensional sparse text features, and cases where you want a robust classical baseline. Linear SVMs were historically excellent for text classification.
They are less attractive for very large datasets because kernel SVM training scales poorly with number of examples. They also do not naturally produce calibrated probabilities.
Senior/staff considerations#
A senior answer should mention operational tradeoffs. If you need calibrated probabilities, use Platt scaling or choose logistic regression. If you have millions of examples, prefer linear models, GBDTs, or neural models. If you have tabular heterogeneous features, GBDTs usually beat SVMs with less tuning.
SVMs are most valuable in interviews as a test of geometric thinking: margin, regularization, kernels, and the difference between feature-space expressiveness and computational cost.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
SVMs learn maximum-margin classifiers. Soft-margin SVMs trade margin against violations through C. Kernels allow nonlinear boundaries through implicit feature maps, but kernel SVMs can be expensive at scale and need calibration for probabilities.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- How do
Cand RBFgammaaffect overfitting? - Why might logistic regression be preferable if you need probabilities?
- Why do kernel methods scale poorly with large datasets?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions
Explain logistic regression and why it's still used in industry
Explain ensemble methods — random forests and gradient boosting
How do decision trees split? Walk me through Gini impurity vs information gain.
Implement k-nearest neighbors with efficient distance computation