What parameter represents sigma in scikitleans Support Vector Machine?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
In scikit-learn’s SVM implementation, the parameter that corresponds to sigma from the Gaussian or RBF kernel formula is gamma. They are not equal, but they are directly related: gamma = 1 / (2 * sigma^2). So if a textbook or paper gives you sigma, you convert it to gamma before passing it to SVC or SVR with an RBF kernel.
Where sigma Comes From
Many explanations of the Gaussian kernel write it like this:
- '
K(x, y) = exp(-||x - y||^2 / (2 * sigma^2))'
In scikit-learn, the same kernel is parameterized as:
- '
K(x, y) = exp(-gamma * ||x - y||^2)'
Matching the two expressions gives the conversion:
- '
gamma = 1 / (2 * sigma^2)'
That is why there is no separate sigma argument in scikit-learn’s SVM API.
Convert sigma to gamma
If you already know the sigma value you want, compute gamma explicitly.
Then use that value in the classifier.
This is the cleanest way to translate formulas from notes, papers, or older code examples into scikit-learn.
What gamma Controls Intuitively
The gamma value controls how far the influence of each training example reaches.
- large
gammameans very local influence and more complex decision boundaries - small
gammameans broader influence and smoother decision boundaries
Because of the inverse-square relationship, larger sigma means smaller gamma.
That relationship often confuses people at first: increasing sigma makes the kernel wider, while increasing gamma makes it narrower.
Example with a Model
A small example:
If you tune the model with grid search, you normally search over gamma directly because that is what the library exposes.
This Only Applies to the RBF-Style Kernel
The sigma relationship matters for the Gaussian-style RBF kernel. It does not apply the same way to the linear kernel, and it is not the same tuning story for polynomial or sigmoid kernels.
So if you are using kernel="linear", there is no hidden sigma parameter to look for.
Scale Features Before Tuning
The gamma value interacts strongly with feature scale. If one feature spans thousands while another spans fractions, the kernel distance calculation becomes hard to interpret and the sigma to gamma conversion is less useful in practice. Standardizing features before tuning usually makes the parameter search much more meaningful.
Common Pitfalls
- Looking for a literal
sigmaparameter in scikit-learn’sSVCAPI. - Treating
gammaas if it were numerically equal tosigma. - Forgetting the square in the conversion formula.
- Applying the
sigmatogammaconversion to non-RBF kernels. - Tuning
gammawithout scaling features first, which often makes the search misleading.
Summary
- In scikit-learn SVMs,
gammais the parameter that corresponds to Gaussian-kernelsigma. - The conversion is
gamma = 1 / (2 * sigma^2). - Use that conversion when translating formulas from books or papers.
- The relationship matters for RBF-style kernels, not for every kernel choice.
- Larger
sigmameans smallergamma, and largergammameans tighter local influence.
Related reading
- What preprocessing.scale do? How does it work?
- What the impact of different dimension of image resizer when using default config of object detection api
- What this error means y argument is not supported when using python generator as input
- What to do first Feature Selection or Model `Parameters` Setting?
- What to do when Seq2Seq network repeats words over and over in output?
- What to do when Seq2Seq network repeats words over and over in output?
- What type of algorithm should i use?
- What type of neural network can handle variable input and output sizes?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.