scikit-learn
Support Vector Machine
SVM parameters
sigma
machine learning

What parameter represents sigma in scikitleans Support Vector Machine?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

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.

python
sigma = 2.0
gamma = 1.0 / (2.0 * sigma ** 2)
print(gamma)

Then use that value in the classifier.

python
1from sklearn.svm import SVC
2
3sigma = 2.0
4gamma = 1.0 / (2.0 * sigma ** 2)
5
6model = SVC(kernel="rbf", gamma=gamma)

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 gamma means very local influence and more complex decision boundaries
  • small gamma means 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:

python
1from sklearn.datasets import load_iris
2from sklearn.model_selection import train_test_split
3from sklearn.svm import SVC
4
5X, y = load_iris(return_X_y=True)
6X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
7
8sigma = 1.5
9gamma = 1.0 / (2.0 * sigma ** 2)
10
11model = SVC(kernel="rbf", gamma=gamma)
12model.fit(X_train, y_train)
13print(model.score(X_test, y_test))

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 sigma parameter in scikit-learn’s SVC API.
  • Treating gamma as if it were numerically equal to sigma.
  • Forgetting the square in the conversion formula.
  • Applying the sigma to gamma conversion to non-RBF kernels.
  • Tuning gamma without scaling features first, which often makes the search misleading.

Summary

  • In scikit-learn SVMs, gamma is the parameter that corresponds to Gaussian-kernel sigma.
  • 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 sigma means smaller gamma, and larger gamma means tighter local influence.

Course illustration
Course illustration

All Rights Reserved.