Skip to main content

OneClassSVM

OneClassSVM performs unsupervised outlier / novelty detection by fitting the one-class nu-SVM dual with a dedicated SMO solver.

Algorithm

The estimator solves a quadratic program over the dual coefficients with a unit sum constraint and a box bound 1 / (nu * n), then computes an offset rho from the support vectors. The decision function is the kernel-weighted sum of the dual coefficients minus rho; predict returns +1 for inliers and -1 for outliers.

Constructor

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

Parameters

ParameterDefaultDescription
kernelRBFKernel function.
gamma0Kernel coefficient; 0 means 1 / (n_features * var).
nu0.5Upper bound on the outlier fraction and lower bound on the support-vector fraction, in (0, 1].

Methods

MethodDescription
fit(X)Fit the one-class model.
score_samples(X)Unshifted kernel scores.
decision_function(X)Scores shifted by offset().
predict(X)+1 inlier / -1 outlier.

Fitted Attributes

AccessorDescription
support()Indices of the support vectors.
n_support()Number of support vectors.
dual_coef()Dual coefficients of the support vectors.
offset()Decision offset (-rho).

Example

#include <Skigen/SVM>

using K = Skigen::OneClassSVM<double>::Kernel;
Skigen::OneClassSVM<double> det(K::RBF, 3, 0.0, 0.0, /*nu=*/0.2);
det.fit(X);
Eigen::VectorXi labels = det.predict(X);

Parity Scope

Mirrors the dense scoring and labeling semantics of sklearn.svm.OneClassSVM. The simplified SMO solver 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. Sparse input is deferred.

API Reference

For full signatures see the OneClassSVM API Reference.