Anomaly scores

The reconstruction errors of an autoencoder are per-sample and per-feature: for every input sample there is a vector of residuals (prediction minus actual value). An AnomalyScore reduces that vector to a single scalar score per sample. Samples with high scores deviate strongly from the learned normal behaviour and are therefore candidate anomalies.

The chosen score is configured under train.anomaly_score in the YAML config. This page explains the available scores, how they differ and when to use which, and recommends: RMSEScore as the default.

Note

An anomaly score only ranks samples; it does not classify them. The actual anomaly decision (normal vs. anomalous) is taken afterwards by a ThresholdSelector.

Available scores

Class

Typical config names (train.anomaly_score.name)

Description

RMSEScore

"rmse", "RMSE"

Root-mean-square reconstruction error over all features. Recommended default.

WeightedRMSEScore

"weighted_rmse", "WeightedRMSE"

RMSE where selected features can be up- or down-weighted.

MahalanobisScore

"mahalanobis", "Mahalanobis"

Correlation-aware Mahalanobis distance.

Weighted RMSE

WeightedRMSEScore extends RMSE by allowing per-feature weights, so that deviations on sensor/feature values you care most about contribute more to the final score. The reconstruction errors are first standardised (to remove model bias towards high-magnitude features) and then multiplied by the feature weight before taking the per-sample root mean square.

Choosing a weight:

  • weight > 1 increases the influence of a feature (deviations on it are treated as more suspicious),

  • 0 <= weight < 1 decreases its influence,

  • a weight of 0 ignores the feature,

  • features are not required to have an entry; omitted features keep weight 1.

train:
  anomaly_score:
    name: weighted_rmse
    params:
      feature_weights:
        rotor_speed: 2.0     # emphasise this sensor
        temperature_11: 0.5  # de-emphasise this sensor
        # any other feature keeps weight 1.0

Note

WeightedRMSEScore requires the input to be a DataFrame so that the weights can be matched to the feature names. Negative weights are not allowed.

Use weighted RMSE when you have domain knowledge about which features are most relevant for the faults of interest and want that prior to influence the anomaly score directly.

Mahalanobis

MahalanobisScore computes the Mahalanobis distance, which unlike RMSE accounts for the correlation between features. Instead of summing independent standardised errors, it measures the distance in units of the covariance of the (mean-centred) errors:

s_i = \sqrt{(x_i - \mu)^{\top} \Sigma^{-1} (x_i - \mu)}

The covariance estimator is chosen via the covariance_method parameter:

covariance_method

Behaviour

"auto" (default)

Use MinCovDet when it is stable, otherwise fall back to a shrinkage estimator (see below).

"min_cov_det"

Always use Minimum Covariance Determinant (robust, but requires enough samples).

"shrinkage"

Always use a shrinkage estimator (Ledoit-Wolf / OAS). Robust for high-dimensional data.

Advantages

Limitations

Accounts for correlation between features; can separate faults that RMSE cannot.

More computationally expensive and more complex than RMSE.

Robust (MinCovDet) or high-dimensional-friendly (shrinkage) variants available.

Sensitive to covariance estimation quality.

Use the Mahalanobis score when features are strongly correlated and you need a correlation-aware score, but reserve it for cases where the added complexity is justified.

The derived stability threshold

MinCovDet needs enough samples per feature: as the sample-to-feature ratio n / p drops it quickly becomes unstable (its covariance becomes rank-deficient and ill-conditioned). Concretely:

  • for n / p >= min_cov_det_ratio (default 2.0) the covariance is well conditioned and MinCovDet is usable;

  • below that, or when the covariance is singular / ill-conditioned, a shrinkage estimator (Ledoit-Wolf / OAS) should be used instead.

With covariance_method="auto" this threshold is applied automatically and the estimator falls back to shrinkage (Ledoit-Wolf / OAS) whenever MinCovDet would be unstable.

train:
  anomaly_score:
    name: mahalanobis
    params:
      covariance_method: auto     # "auto" | "min_cov_det" | "shrinkage"
      min_cov_det_ratio: 2.0      # minimum n/p for MinCovDet when "auto"
      shrinkage_method: oas       # "oas" | "ledoit_wolf"

Deprecated since version The: legacy pca=True path of MahalanobisScore is deprecated and will be replaced by the clean Mahalanobis norm implementation (pca=False). Likewise the scale parameter is deprecated and no longer has any effect. See Advanced usage and customization for details.

Which score should I use?

Your situation

Recommended score

You want a simple, robust default that works out of the box.

RMSE (name: rmse)

You have domain knowledge about which features matter most for the fault.

Weighted RMSE (name: weighted_rmse)

Features are strongly correlated and a correlation-aware score is important.

Mahalanobis (name: mahalanobis, covariance_method: auto)

High-dimensional input where a stable covariance is hard to estimate.

Mahalanobis with covariance_method: shrinkage (or RMSE)

For most projects the RMSE score is a safe, interpretable and efficient default: it needs no covariance estimation, is stable regardless of the number of samples and features, and pairs well with a good threshold selector. Start with RMSE and move to a more specialised score only when a concrete need arises.