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[]) ~ SweepResultParameters
| Name | Type | Description |
|---|---|---|
| detector | OutlierDetector | the detector |
| settings | Float | sensitivity values, in table order |
| labels | String | a name per setting, e.g. "Low"; Nil to name them by value |
| X | Float | rows x features |
| y | Bool | true labels, true = anomaly |
Return
| Type | Description |
|---|---|
| SweepResult | the 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[]) ~ SweepResultParameters
| Name | Type | Description |
|---|---|---|
| detector | OutlierDetector | the detector (LocalOutlierFactor needs novelty = true) |
| settings | Float | sensitivity values, in table order |
| labels | String | a name per setting; Nil to name them by value |
| X_train | Float | rows to fit on |
| X_test | Float | rows to label |
| y_test | Bool | true labels of X_test, true = anomaly |
Return
| Type | Description |
|---|---|
| SweepResult | the table, or Nil when the inputs do not line up |