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.

ZScoreDetector

Flags rows whose standardized value on some feature is extreme.

Fit stores each feature's mean and population standard deviation (ddof 0, as scipy.stats.zscore). A row's score combines its per-feature |z| by the rule: MAX (default) is max |z|, i.e. "any feature beyond the threshold"; MEAN is the mean |z|; RMS is sqrt(mean z^2), a diagonal Mahalanobis distance over sqrt(p).

The threshold is the absolute value itself (default 3.0); a lower threshold flags more. A feature constant in training contributes |z| = 0 when a value equals the constant and +Inf otherwise.

Implements: OutlierDetector

Example

z := ZScoreDetector->New(2.5);
flags := z->FitPredict(X);          # true where some |z| > 2.5

Operations

DecisionFunction #

Score minus the threshold; 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 per-feature means and standard deviations.

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
Boolone label per row (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

GetMeans #

Per-feature training means.

method : public : GetMeans() ~ Float[]

Return

TypeDescription
Floatmeans, or Nil when unfitted

GetSensitivity #

The z threshold.

method : public : GetSensitivity() ~ Float

Return

TypeDescription
Floatthreshold

GetSensitivityName #

The setting's name.

method : public : GetSensitivityName() ~ String

Return

TypeDescription
String"threshold"

GetStdDevs #

Per-feature training population standard deviations.

method : public : GetStdDevs() ~ Float[]

Return

TypeDescription
Floatstandard deviations, or Nil when unfitted

GetThreshold #

The z threshold.

method : public : GetThreshold() ~ Float

Return

TypeDescription
Floatthreshold

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: threshold 3.0, MAX rule.

New()

New # constructor

Constructor.

New(threshold:Float)

Parameters

NameTypeDescription
thresholdFloatabsolute z threshold (> 0)

New # constructor

Constructor.

New(threshold:Float, rule:ZScoreDetector->Rule)

Parameters

NameTypeDescription
thresholdFloatabsolute z threshold (> 0)
ruleZScoreDetector->Rulehow per-feature |z| values combine

Predict #

Labels rows: true where the combined |z| exceeds the threshold.

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 combined |z| of each row.

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 the z threshold; a fitted detector stays fitted.

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

Parameters

NameTypeDescription
valueFloatthreshold (> 0)

Return

TypeDescription
Boolfalse when value <= 0

ZScores #

Per-feature z values (signed) for each row.

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

Parameters

NameTypeDescription
XFloatrows x features

Return

TypeDescription
Floatrows x features z matrix, or Nil when unfitted or the input is refused