Skip to main content

NuSVC

NuSVC is a nu-parametrised binary support vector classifier. Instead of the penalty C, it uses nu, which bounds the fraction of margin errors and support vectors.

Algorithm

The estimator solves the nu-SVM dual with a dedicated SMO variant. Two equality constraints — one per class on the dual sums — replace the single equality of the C-SVM. Each class is initialised to a uniform mass nu * n / 2, and optimisation works on pairs within the same class so the per-class sums are preserved under a [0, 1] box bound. The intercept is recovered from the free support vectors. The decision function is the kernel-weighted sum of dual_coef_ plus the intercept; predict returns the class with the matching sign.

Constructor

Skigen::NuSVC<Scalar> model(
Scalar nu = 0.5,
Kernel kernel = Kernel::RBF,
int degree = 3,
Scalar gamma = 0,
Scalar coef0 = 0,
Scalar tol = 1e-3,
int max_passes = 50,
std::optional<uint64_t> random_state = std::nullopt);

Parameters

ParameterDefaultDescription
nu0.5Upper bound on the fraction of margin errors and lower bound on the fraction of support vectors, in (0, 1]. Infeasible values throw std::invalid_argument.
kernelRBFKernel function.
gamma0Kernel coefficient; 0 means 1 / (n_features * var).

Methods

MethodDescription
fit(X, y)Fit the nu-SVM classifier; requires exactly two classes.
decision_function(X)Signed kernel scores.
predict(X)Predicted class labels.

Fitted Attributes

AccessorDescription
support()Indices of the support vectors.
n_support()Number of support vectors.
classes()The two class labels seen during fit.
intercept()Decision intercept.

Example

#include <Skigen/SVM>

using K = Skigen::NuSVC<double>::Kernel;
Skigen::NuSVC<double> clf(/*nu=*/0.5, K::RBF);
clf.fit(X, y);
Eigen::VectorXi labels = clf.predict(X);

Parity Scope

Mirrors the dense sklearn.svm.NuSVC API surface and labelling semantics. The simplified nu-SMO targets the same optimum as libsvm but uses a first-order working set, so exact support-vector counts and decision values may differ on hard instances. Multi-class one-vs-one and sparse input are deferred.

API Reference

For full signatures see the NuSVC API Reference.