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.
Example
svm := OneClassSvmDetector->New(SvmKernel->RBF, 0.05);
flags := svm->FitPredict(X);Operations
- New
- DecisionFunction
- Fit
- FitPredict
- GetError
- GetModel
- GetSensitivity
- GetSensitivityName
- GetThreshold
- GetTrainingScores
- IsFitted
- Predict
- Score
- SetSensitivity
DecisionFunction #
Score minus the threshold 0.0, i.e. the negated decision value; positive means outlier.
method : public : DecisionFunction(X:Float[,]) ~ Float[]Parameters
| Name | Type | Description |
|---|---|---|
| X | Float | rows x features |
Return
| Type | Description |
|---|---|
| Float | values, or Nil when unfitted or the input is refused |
Fit #
Fits the boundary.
method : public : Fit(X:Float[,]) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| X | Float | rows x features |
Return
| Type | Description |
|---|---|
| Bool | true on success |
FitPredict #
Fits, then labels the training rows.
method : public : FitPredict(X:Float[,]) ~ Bool[]Parameters
| Name | Type | Description |
|---|---|---|
| X | Float | rows x features |
Return
| Type | Description |
|---|---|
| Bool | labels (true = outlier), or Nil when the fit failed |
GetError #
Why the last call failed.
method : public : GetError() ~ StringReturn
| Type | Description |
|---|---|
| String | the reason, or an empty string |
GetModel #
The wrapped OneClassSVM.
method : public : GetModel() ~ OneClassSVMReturn
| Type | Description |
|---|---|
| OneClassSVM | the model |
GetSensitivityName #
The setting's name.
method : public : GetSensitivityName() ~ StringReturn
| Type | Description |
|---|---|
| String | "nu" |
GetThreshold #
The threshold on Score, which is 0.0: the boundary itself.
method : public : GetThreshold() ~ FloatReturn
| Type | Description |
|---|---|
| Float | 0.0 |
GetTrainingScores #
The training rows' scores.
method : public : GetTrainingScores() ~ Float[]Return
| Type | Description |
|---|---|
| Float | scores, or Nil when unfitted |
IsFitted #
Whether the detector is fitted.
method : public : IsFitted() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true when fitted |
New # constructor
Constructor; gamma is 'scale'.
New(kernel:SvmKernel, nu:Float)Parameters
| Name | Type | Description |
|---|---|---|
| kernel | SvmKernel | kernel function |
| nu | Float | bound 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
| Name | Type | Description |
|---|---|---|
| model | OneClassSVM | the one-class SVM |
Predict #
Labels rows: true where the decision value is below 0 (outside the boundary).
method : public : Predict(X:Float[,]) ~ Bool[]Parameters
| Name | Type | Description |
|---|---|---|
| X | Float | rows x features |
Return
| Type | Description |
|---|---|
| Bool | labels, or Nil when unfitted or the input is refused |