Kernel intuition and RBF gamma
Quick answer
A kernel supplies similarities corresponding to inner products in a feature space. The radial basis function (RBF) kernel decreases with squared distance, allowing an SVM to form curved boundaries without explicitly building all transformed coordinates. Static examples tested locally with Python 3.13.5, scikit-learn 1.8.0 and NumPy 2.3.5 where imported. ByteMind package execution is unverified.
Compare kernel values
from math import expprint([round(exp(-0.5*d),4) for d in [0,1,4]])Observed local output:
[1.0, 0.6065, 0.1353]Similarity falls as squared distance increases.
How it works
The linear kernel K(x,z)=x·z returns an inner product. The RBF kernel K(x,z)=exp(-gamma*||x-z||²), gamma>0, equals one for identical inputs and falls toward zero as distance grows. For x=(1,2) and z=(4,6), squared distance is 25; with gamma=0.04 the similarity is exp(-1), about 0.368. The kernel trick evaluates these inner products directly. An arbitrary similarity function is not necessarily a valid positive semidefinite kernel: a Gram matrix for a valid real kernel must be symmetric and positive semidefinite for every finite set. Large gamma means more local influence, small gamma broader influence; neither is an accuracy guarantee. Feature units affect distances, so scaling can materially change the model. In SVC 1.8 gamma="scale" is computed from the input seen by the estimator as 1/(n_features*X.var()) when variance is nonzero; gamma="auto" uses 1/n_features. A numeric gamma is fixed. With a preprocessing pipeline, these calculations use the transformed training inputs. Polynomial kernels are another option, with degree and coefficient parameters; the core example compares linear and RBF. For precomputed kernels, training uses a square Gram matrix and inference uses rows against the training columns in the original order; never use test-to-test similarities as a replacement.
Fit an XOR boundary
from sklearn.svm import SVCX=[[0,0],[0,1],[1,0],[1,1]]; y=[0,1,1,0]for k in ["linear","rbf"]: m=SVC(kernel=k,C=10,gamma=2).fit(X,y) print(k,round(m.score(X,y),2))Observed local output:
linear 0.5rbf 1.0The linear boundary cannot separate this XOR fixture. These are training scores, not generalization evidence.
Common mistakes
Do not substitute Euclidean distance for squared distance in the exponent. Do not interpret gamma as a learning rate or an RBF similarity as a class probability. Large gamma does not guarantee a better fit on new data. Do not compute a data-dependent transform on all rows before validation.
Practice and next steps
Compute RBF similarities for squared distances 0,1,4 at gamma=0.5, then at gamma=2. Explain which setting is more local. Fit the XOR fixture with different C and gamma values, then move to the held-out project rather than evaluating training rows alone. Complete the knowledge check and staged exercise. Next: Support vector regression.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Kernel intuition and RBF gamma — knowledge check
Apply kernel intuition and rbf gamma to new scenarios.
RBF similarity of identical inputs?
For a fixed nonzero distance, increasing gamma?
Which property must a valid real kernel Gram matrix have?
Why can RBF fit XOR?
Which rows are columns in a precomputed test kernel?