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.
Example
z := ZScoreDetector->New(2.5);
flags := z->FitPredict(X); # true where some |z| > 2.5Operations
- New
- DecisionFunction
- Fit
- FitPredict
- GetError
- GetMeans
- GetSensitivity
- GetSensitivityName
- GetStdDevs
- GetThreshold
- GetTrainingScores
- IsFitted
- Predict
- Score
- SetSensitivity
- ZScores
DecisionFunction #
Score minus the threshold; 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 per-feature means and standard deviations.
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 | one label per row (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 |
GetMeans #
Per-feature training means.
method : public : GetMeans() ~ Float[]Return
| Type | Description |
|---|---|
| Float | means, or Nil when unfitted |
GetSensitivity #
The z threshold.
method : public : GetSensitivity() ~ FloatReturn
| Type | Description |
|---|---|
| Float | threshold |
GetSensitivityName #
The setting's name.
method : public : GetSensitivityName() ~ StringReturn
| Type | Description |
|---|---|
| String | "threshold" |
GetStdDevs #
Per-feature training population standard deviations.
method : public : GetStdDevs() ~ Float[]Return
| Type | Description |
|---|---|
| Float | standard deviations, or Nil when unfitted |
GetThreshold #
The z threshold.
method : public : GetThreshold() ~ FloatReturn
| Type | Description |
|---|---|
| Float | threshold |
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.
New(threshold:Float)Parameters
| Name | Type | Description |
|---|---|---|
| threshold | Float | absolute z threshold (> 0) |
New # constructor
Constructor.
New(threshold:Float, rule:ZScoreDetector->Rule)Parameters
| Name | Type | Description |
|---|---|---|
| threshold | Float | absolute z threshold (> 0) |
| rule | ZScoreDetector->Rule | how per-feature |z| values combine |
Predict #
Labels rows: true where the combined |z| exceeds the threshold.
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 |
Score #
The combined |z| of each row.
method : public : Score(X:Float[,]) ~ Float[]Parameters
| Name | Type | Description |
|---|---|---|
| X | Float | rows x features |
Return
| Type | Description |
|---|---|
| Float | scores, or Nil when unfitted or the input is refused |