OneClassSVM
#include <Skigen/SVM>
template <typename Scalar = double>
class Skigen::OneClassSVM(kernel=Kernel::RBF, degree=3, gamma=0, coef0=0, nu=0.5, tol=1e-3, max_passes=50, random_state=std::nullopt)
Unsupervised outlier detection with a one-class SVM.
Solves the one-class nu-SVM dual with a dedicated SMO variant and exposes sklearn-style scoring: decision_function, score_samples, predict (+1 inlier, -1 outlier), and offset_.
Mirrors the dense core of sklearn.svm.OneClassSVM.
Attributes:
-
kernel : Kernel
-
gamma : Scalar
-
nu : Scalar
-
support : const std::vector< Eigen::Index > &
-
n_support : int
-
dual_coef : VectorType
-
offset : Scalar
Methods
SKIGEN_PARAMS()
decision_function(X)
Signed distance to the separating hyperplane (rho-shifted).
score_samples(X)
Unshifted kernel score for each sample.
predict(X)
Predict +1 for inliers and -1 for outliers.
Example
Eigen::MatrixXd X(12, 2);
for (int i = 0; i < 10; ++i) {
X(i, 0) = 0.2 * std::sin(static_cast<double>(i));
X(i, 1) = 0.2 * std::cos(static_cast<double>(i));
}
X(10, 0) = 6.0; X(10, 1) = 6.0;
X(11, 0) = -6.0; X(11, 1) = 5.0;
using K = Skigen::OneClassSVM<double>::Kernel;
Skigen::OneClassSVM<double> det(K::RBF, 3, 0.0, 0.0, /*nu=*/0.2);
det.fit(X);
const Eigen::VectorXi labels = det.predict(X);