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.

SensitivitySweep

Runs one OutlierDetector at several sensitivity settings and scores each setting's labels against the truth: precision, recall, F1 and false-positive rate per setting, as a table.

Any detector works through the interface, so a detector added later (One-Class SVM, say) needs nothing here. Each setting goes through SetSensitivity, and the detector decides whether that needs a refit: a setting that only moves the threshold (a z-score threshold, a contamination, an autoencoder percentile) reuses the fitted model and its scores; one that changes the model (DBSCAN's eps, One-Class SVM's nu) leaves the detector unfitted and the sweep fits it again. The first setting always fits, so the detector's earlier state never leaks into the table.

A setting the detector rejects, or a fit that fails, is recorded with its error and the sweep goes on.

Example

detector := ZScoreDetector->New();
result := SensitivitySweep->Run(detector, [3.0, 2.5, 2.0], ["Low", "Medium", "High"], X, y);
result->ToTable()->PrintLine();

Operations

Run # function

Fits and labels the same rows (the usual unsupervised lab: flag the training data itself, then compare with the labels). Uses FitPredict semantics, so LocalOutlierFactor without novelty and DbscanDetector work.

function : Run(detector:OutlierDetector, settings:Float[], labels:String[], X:Float[,], y:Bool[]) ~ SweepResult

Parameters

NameTypeDescription
detectorOutlierDetectorthe detector
settingsFloatsensitivity values, in table order
labelsStringa name per setting, e.g. "Low"; Nil to name them by value
XFloatrows x features
yBooltrue labels, true = anomaly

Return

TypeDescription
SweepResultthe table, or Nil when the inputs do not line up

Run # function

Fits on training rows and labels held-out rows with Predict.

function : Run(detector:OutlierDetector, settings:Float[], labels:String[], X_train:Float[,], X_test:Float[,], y_test:Bool[]) ~ SweepResult

Parameters

NameTypeDescription
detectorOutlierDetectorthe detector (LocalOutlierFactor needs novelty = true)
settingsFloatsensitivity values, in table order
labelsStringa name per setting; Nil to name them by value
X_trainFloatrows to fit on
X_testFloatrows to label
y_testBooltrue labels of X_test, true = anomaly

Return

TypeDescription
SweepResultthe table, or Nil when the inputs do not line up