v2026.11.2
All Bundles
Bundle

Core machine learning types: the seedable Random generator, Matrix2D linear algebra and activations, matrix reference holders, the NeuralNetwork and CSV-backed MatrixReader. Compile with -lib ml.

OneClassSvmDetector

One-Class SVM as an OutlierDetector, so nu can be swept like any other detector's setting. A thin adapter over OneClassSVM (ml_svm.obs), which keeps scikit-learn's signs: its DecisionFunction is positive inside the boundary and its Predict answers +1 / -1. Here, as for every OutlierDetector, Predict is Bool with true = outlier and Score is higher-is-more-anomalous: Score is OneClassSVM's PredictScore, the negated decision value, the threshold is 0.0, and a row is an outlier when its decision value is below 0 -- exactly OneClassSVM->IsOutlier and scikit-learn's predict.

nu is the sensitivity setting: an upper bound on the training fraction strictly outside and a lower bound on the support-vector fraction. It changes the model, so SetSensitivity unfits the detector. Defaults are scikit-learn's: RBF kernel, nu 0.5, gamma 'scale'. The flagged training fraction can exceed nu: the free support vectors sit on the boundary, decision 0 to within the solver's tolerance, and those just below 0 are flagged (see OneClassSVM's notes on nu). A OneClassSVM configured through New(model) -- a tighter SetTolerance, say -- keeps its settings when SetSensitivity changes nu.

Implements: OutlierDetector

Example

svm := OneClassSvmDetector->New(SvmKernel->RBF, 0.05);
flags := svm->FitPredict(X);

Operations

DecisionFunction #

Score minus the threshold 0.0, i.e. the negated decision value; positive means outlier.

method : public : DecisionFunction(X:Float[,]) ~ Float[]

Parameters

NameTypeDescription
XFloatrows x features

Return

TypeDescription
Floatvalues, or Nil when unfitted or the input is refused

Fit #

Fits the boundary.

method : public : Fit(X:Float[,]) ~ Bool

Parameters

NameTypeDescription
XFloatrows x features

Return

TypeDescription
Booltrue on success

FitPredict #

Fits, then labels the training rows.

method : public : FitPredict(X:Float[,]) ~ Bool[]

Parameters

NameTypeDescription
XFloatrows x features

Return

TypeDescription
Boollabels (true = outlier), or Nil when the fit failed

GetError #

Why the last call failed.

method : public : GetError() ~ String

Return

TypeDescription
Stringthe reason, or an empty string

GetModel #

The wrapped OneClassSVM.

method : public : GetModel() ~ OneClassSVM

Return

TypeDescription
OneClassSVMthe model

GetSensitivity #

nu.

method : public : GetSensitivity() ~ Float

Return

TypeDescription
Floatnu

GetSensitivityName #

The setting's name.

method : public : GetSensitivityName() ~ String

Return

TypeDescription
String"nu"

GetThreshold #

The threshold on Score, which is 0.0: the boundary itself.

method : public : GetThreshold() ~ Float

Return

TypeDescription
Float0.0

GetTrainingScores #

The training rows' scores.

method : public : GetTrainingScores() ~ Float[]

Return

TypeDescription
Floatscores, or Nil when unfitted

IsFitted #

Whether the detector is fitted.

method : public : IsFitted() ~ Bool

Return

TypeDescription
Booltrue when fitted

New # constructor

Constructor with scikit-learn's defaults: RBF kernel, nu 0.5, gamma 'scale'.

New()

New # constructor

Constructor; gamma is 'scale'.

New(kernel:SvmKernel, nu:Float)

Parameters

NameTypeDescription
kernelSvmKernelkernel function
nuFloatbound on the training outlier fraction, in (0, 1]

New # constructor

Wraps a configured OneClassSVM (kernel, gamma, tolerance and so on are kept; SetSensitivity changes its nu).

New(model:OneClassSVM)

Parameters

NameTypeDescription
modelOneClassSVMthe one-class SVM

Predict #

Labels rows: true where the decision value is below 0 (outside the boundary).

method : public : Predict(X:Float[,]) ~ Bool[]

Parameters

NameTypeDescription
XFloatrows x features

Return

TypeDescription
Boollabels, or Nil when unfitted or the input is refused

Score #

The negated decision value: higher means more anomalous.

method : public : Score(X:Float[,]) ~ Float[]

Parameters

NameTypeDescription
XFloatrows x features

Return

TypeDescription
Floatscores, or Nil when unfitted or the input is refused

SetSensitivity #

Sets nu; the detector becomes unfitted, since nu changes the boundary.

method : public : SetSensitivity(value:Float) ~ Bool

Parameters

NameTypeDescription
valueFloatnu in (0, 1]

Return

TypeDescription
Boolfalse when out of range