scikit-learn SVC with RBF
The default tabular non-linear baseline. Works well on small/medium datasets where deep learning would overfit.
from sklearn.svm import SVC
clf = SVC(kernel='rbf', C=1.0, gamma='scale').fit(X, y)Name things for the reader, not the writer.
Name things for the reader, not the writer.
Support Vector Machines
Linear SVMs can only draw straight decision boundaries — yet most interesting data is non-linearly separable. The kernel trick turns linear SVMs into universal classifiers without ever computing features explicitly. The insight comes from the dual: it depends on mathbf{x}_n only via inner products m
The kernel trick replaces with — implicit feature lifting without explicit computation.
Linear SVMs can only draw straight decision boundaries — yet most interesting data is non-linearly separable. The kernel trick turns linear SVMs into universal classifiers without ever computing features explicitly. The insight comes from the dual: it depends on only via inner products . Replace every such inner product with a kernel function , and you are implicitly operating in a different feature space such that — without ever computing .
The kernelized dual is and the decision function is a kernel-weighted sum over support vectors. A valid kernel must be positive semi-definite (Mercer's condition): for any , the Gram matrix must be PSD. Only such kernels correspond to genuine inner products in some feature space.
Three kernels power 90% of applications. Polynomial implicitly maps into degree- polynomial features — cheap and interpretable. Radial Basis Function (RBF) maps into an infinite-dimensional feature space and is the default choice for most problems. Sigmoid (not always PSD — careful) gives a shallow neural network flavor.
Kernel choice and hyperparameters are the main modeling decisions. The RBF bandwidth controls smoothness: small gives a highly flexible, wiggly boundary (risk of overfitting); large gives a nearly linear boundary (risk of underfitting). Combined with the penalty , RBF SVMs have two hyperparameters — — which are usually selected by cross-validation over a log-spaced grid. This simplicity and strong regularization is why RBF SVMs were the state of the art on many tasks for decades.
Beyond SVMs, kernels power kernel ridge regression, Gaussian processes, kernel PCA, and kernel $k$-means. They illustrate a profound principle: any algorithm that uses data only via inner products can be kernelized. The cost is memory for the Gram matrix, which limits classical kernels to tens of thousands of points. Modern scalable variants — Nystrom approximations, random features (Rahimi-Recht), and neural tangent kernels — preserve the kernel mindset while scaling to millions of samples.
Python (in browser)
Expected: RBF significantly outperforms linear on this non-linearly-separable dataset
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
The default tabular non-linear baseline. Works well on small/medium datasets where deep learning would overfit.
from sklearn.svm import SVC
clf = SVC(kernel='rbf', C=1.0, gamma='scale').fit(X, y)Weisfeiler-Lehman and graph-edit kernels let you SVM-classify molecular graphs without learning a representation — still competitive on small chemistry datasets.
FAVOR+ replaces softmax attention with a random-feature kernel approximation, making attention linear in sequence length.
Put your understanding to the test. Score + streak + speed all count.
3 quick questions. Get 2 right to mark this lesson complete.