RBF-kernel classification
Classification with nonlinear class boundaries.
Scikit-Learn · Class
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.
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.
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)| Name | Type | Description |
|---|---|---|
nu | float, default=0.5 | Upper 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. |
degree | int, default=3 | Polynomial-kernel degree; must be non-negative. |
gamma | {'scale', 'auto'} or float, default='scale' | Kernel coefficient for rbf, poly, and sigmoid kernels. |
coef0 | float, default=0.0 | Independent term in the polynomial and sigmoid kernels. |
shrinking | bool, default=True | Whether to use the shrinking heuristic. |
probability | bool, default=False | Whether to enable probability estimates. |
tol | float, default=0.001 | Stopping tolerance. |
cache_size | float, default=200 | Kernel-cache size in megabytes. |
class_weight | dict or 'balanced', default=None | Class weights; use 'balanced' for automatic weighting or a mapping. |
verbose | bool, default=False | Enable verbose output. |
max_iter | int, default=-1 | Hard limit on solver iterations; -1 means no limit. |
A fitted NuSVC estimator from fit; prediction methods return class labels or decision scores as documented.
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.
Classification with nonlinear class boundaries.
Models where support-vector and margin-error fractions should be controlled directly.
Classification with custom similarity functions or precomputed kernel matrices.
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.
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.
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.
SVCLinearSVCNuSVROneClassSVMsklearn.svm