Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Class

NuSVC

NuSVC is a support-vector classifier whose nu parameter controls the allowed fraction of margin errors and the minimum fraction of support vectors. It supports multiple kernel types, including the default RBF kernel.

How it works

NuSVC is a support-vector classifier that replaces the usual C parameter with nu. The nu value constrains the fraction of margin errors from above and support vectors from below, while kernel settings determine the decision boundary.

Syntax

class sklearn.svm.NuSVC(*, nu=0.5, kernel='rbf', degree=3, gamma='scale', coef0=0.0, shrinking=True, probability=False, tol=0.001, cache_size=200, class_weight=None, verbose=False, max_iter=-1, decision_function_shape='ovr', break_ties=False, random_state=None)

Parameters

NameTypeDescription
nufloat, default=0.5Upper bound on the fraction of margin errors and lower bound on the fraction of support vectors; must lie in (0, 1].
kernel{'linear', 'poly', 'rbf', 'sigmoid', 'precomputed'} or callable, default='rbf'Kernel type: linear, poly, rbf, sigmoid, precomputed, or a callable.
degreeint, default=3Polynomial-kernel degree; must be non-negative.
gamma{'scale', 'auto'} or float, default='scale'Kernel coefficient for rbf, poly, and sigmoid kernels.
coef0float, default=0.0Independent term in the polynomial and sigmoid kernels.
shrinkingbool, default=TrueWhether to use the shrinking heuristic.
probabilitybool, default=FalseWhether to enable probability estimates.
tolfloat, default=0.001Stopping tolerance.
cache_sizefloat, default=200Kernel-cache size in megabytes.
class_weightdict or 'balanced', default=NoneClass weights; use 'balanced' for automatic weighting or a mapping.
verbosebool, default=FalseEnable verbose output.
max_iterint, default=-1Hard limit on solver iterations; -1 means no limit.

Returns

A fitted NuSVC estimator from fit; prediction methods return class labels or decision scores as documented.

Key points

  • NuSVC is the scikit-learn classifier implementing the Nu-SVM formulation.
  • Its defining difference from SVC is the nu parameter, which directly regulates support-vector and margin-error fractions.
  • The estimator uses the libsvm implementation underneath.
  • Leaving kernel unchanged selects the radial-basis-function kernel.
  • nu limits the proportion of training samples counted as margin errors from above.
  • nu also imposes a lower bound on the proportion of support vectors.

Common mistakes

  • nu must be greater than 0 and no greater than 1.
  • Probability estimates are disabled by default; enable them with probability=True when predict_proba or predict_log_proba is needed.
  • The polynomial kernel degree cannot be negative.

Example: Train and predict with NuSVC

from sklearn.svm import NuSVC

X = [[0, 0], [1, 1], [0, 1], [1, 0]]
y = [0, 1, 1, 0]

model = NuSVC(nu=0.5, kernel="rbf", gamma="scale")
model.fit(X, y)
print(model.predict([[0.2, 0.8]]))

Creates an RBF Nu-SVM classifier, fits it to labeled samples, and predicts a class for a new sample.

When to use it

RBF-kernel classification

Classification with nonlinear class boundaries.

Nu-constrained classification

Models where support-vector and margin-error fractions should be controlled directly.

Custom-kernel classification

Classification with custom similarity functions or precomputed kernel matrices.

Interview questions

QWhat is NuSVC, and how does it differ from SVC?

NuSVC performs Nu-Support Vector Classification using libsvm. It resembles SVC, but nu controls the number of support vectors and margin errors instead of C.

Follow-up: How does nu constrain the fitted model? It is an upper bound on the fraction of margin errors and a lower bound on the fraction of support vectors.

QWhich kernels can NuSVC use?

The default kernel is the radial-basis-function kernel, represented by kernel='rbf'. Other documented choices include linear, polynomial, sigmoid, precomputed, or a callable kernel.

Follow-up: What does a callable kernel do? It is used to precompute the kernel matrix supplied to the estimator.

QWhat data can NuSVC consume, and what outputs can it produce?

NuSVC accepts dense arrays and sparse sample vectors. After fitting, it can classify new samples with predict; decision_function provides class scores, with one score per sample in the binary case.

Follow-up: What must be true when predicting sparse data? The estimator must have been fitted on sparse data as well.

  • SVC
  • LinearSVC
  • NuSVR
  • OneClassSVM
  • sklearn.svm

Source: NuSVC — scikit-learn 1.9.1 documentation. Checked 2026-10-15.