Scikit-Learn
SVM
nu parameter
machine learning
support vector machine

What is the meaning of the nu parameter in Scikit-Learn's SVM class?

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

The nu parameter appears in scikit-learn's NuSVC, NuSVR, and OneClassSVM models. It is a constrained alternative to the more familiar C parameter used in other SVM formulations. The easiest way to think about nu is that it controls how many training points are allowed to violate the margin and how many points must become support vectors, with the exact interpretation depending on the SVM variant.

Where nu Is Used

You do not set nu on every SVM class. It is specific to the Nu* formulations and to OneClassSVM.

Typical examples are:

python
1from sklearn.svm import NuSVC, NuSVR, OneClassSVM
2
3clf = NuSVC(nu=0.3, kernel="rbf")
4reg = NuSVR(nu=0.4, kernel="rbf")
5anomaly = OneClassSVM(nu=0.05, kernel="rbf")

The value must lie in the interval (0, 1].

Meaning in NuSVC

For classification with NuSVC, nu acts as:

  • an upper bound on the fraction of training margin errors
  • a lower bound on the fraction of support vectors

That means larger nu values generally allow a looser margin and force more points to play an active role in the decision boundary.

In practical terms:

  • small nu often leads to a simpler boundary with fewer support vectors
  • larger nu can make the classifier more flexible and more sensitive to the training data

A small example:

python
1from sklearn.datasets import make_classification
2from sklearn.svm import NuSVC
3
4X, y = make_classification(n_samples=200, n_features=4, random_state=42)
5model = NuSVC(nu=0.2, kernel="rbf", gamma="scale")
6model.fit(X, y)
7
8print(len(model.support_))

If you increase nu, you will often see the number of support vectors rise.

Meaning in NuSVR

For NuSVR, the interpretation is related but framed in regression terms rather than strict class separation. nu controls the trade-off between model smoothness and the fraction of training errors or support vectors.

A higher nu generally allows the fitted regression function to rely on more support vectors and to tolerate a different balance of residual error.

python
1from sklearn.datasets import make_regression
2from sklearn.svm import NuSVR
3
4X, y = make_regression(n_samples=200, n_features=3, noise=10, random_state=42)
5model = NuSVR(nu=0.4, kernel="rbf", gamma="scale")
6model.fit(X, y)
7
8print(len(model.support_))

As with NuSVC, changing nu changes how many points influence the model directly.

Meaning in OneClassSVM

For OneClassSVM, nu is usually explained as:

  • an upper bound on the fraction of training errors or outliers
  • a lower bound on the fraction of support vectors

This makes nu especially interpretable in anomaly-detection contexts. If you believe roughly five percent of the training data might be outliers, nu=0.05 is a natural starting point.

python
1import numpy as np
2from sklearn.svm import OneClassSVM
3
4X = np.random.normal(size=(200, 2))
5model = OneClassSVM(nu=0.05, gamma="scale")
6model.fit(X)
7
8pred = model.predict(X[:5])
9print(pred)

The parameter does not guarantee exactly that fraction of outliers, but it constrains the optimization in that direction.

nu Versus C

Many people know C-SVC and SVR, where C is the main regularization knob. The Nu* models provide an alternative parameterization.

The appeal of nu is interpretability. A value such as 0.1 or 0.2 gives you a more direct conceptual handle on support-vector fraction and training error bounds than an abstract penalty constant like C=3.7.

That does not mean nu is automatically easier to tune in every dataset. Kernel choice, feature scaling, and gamma still matter a lot.

Scaling Still Matters

Changing nu will not rescue a poorly scaled feature space. SVMs are sensitive to feature magnitudes, especially with RBF kernels, so standard preprocessing still applies.

python
1from sklearn.pipeline import make_pipeline
2from sklearn.preprocessing import StandardScaler
3from sklearn.svm import NuSVC
4
5model = make_pipeline(
6    StandardScaler(),
7    NuSVC(nu=0.25, kernel="rbf", gamma="scale")
8)

Without proper scaling, interpreting the effect of nu becomes much harder because other geometric distortions dominate the model behavior.

Common Pitfalls

The most common mistake is treating nu as a simple probability or exact fraction. It is a bound in the optimization problem, not a promise about the final observed metric.

Another mistake is tuning nu without scaling the data first. Kernel behavior and margin geometry depend heavily on feature scale.

Developers also sometimes compare nu values across different kernels and datasets as if they had universal meaning. They do not. The effect still depends on the overall model setup.

Finally, nu only applies to certain SVM classes. If you are using ordinary SVC, the main regularization parameter is C, not nu.

Summary

  • 'nu is used in NuSVC, NuSVR, and OneClassSVM.'
  • In broad terms, it sets an upper bound on training errors and a lower bound on support vectors.
  • Larger nu values often produce more support vectors and a more flexible fit.
  • The exact interpretation depends on whether you are doing classification, regression, or novelty detection.
  • Scale your features and tune nu together with kernel-related parameters.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Practice ML system design

All Rights Reserved.