energy_fault_detector.threshold_selectors.fbeta_threshold

class FbetaSelector(beta=0.5, eps=1e-06, quantile=1.0)

Bases: ThresholdSelector

Find a threshold via searching for the optimal fbeta score amongst all options.

Parameters:
  • beta (float) – beta weights the importance between precision and recall in the fbeta score. For example beta=2.0 means recall is twice as important as precision and beta=0.5 means the opposite. Defaults to 0.5.

  • eps (float) – small number, to ensure the optimal threshold is just below the anomaly score resulting in the optimal fbeta score.

  • quantile (float) – optional parameter that can introduce score smoothing. This parameter specifies a quantile which is used during self.fit to neglect all normal anomaly-scores that are greater than the quantile of all normal anomaly-scores. It must be a float between 0 and 1, where 1 practically disables the score smoothing.

threshold

scores above the threshold is classified as anomaly, below is classified as normal.

Type:

float

Configuration example:

train:
  threshold_selector:
    name: FbetaSelector
    params:
      beta: 0.5
      eps: 0.000001
      quantile: 1.
fit(x, y=None)

Selects a threshold based on fbeta-scores.

Parameters:
  • x (Array1D) – numpy array or pandas Series with calculated anomaly scores

  • y (pd.Series) – series of labels indicating whether sample is normal (True) or anomalous (False) Required for F_beta Threshold!

Return type:

FbetaSelector

mark_normal_outliers(anomaly_score, normal_index)

Marks all elements of anomaly_score that are normal according to normal_index which have an anomaly_score that is above the 99% quantile of all normal anomaly_scores

Parameters:
  • anomaly_score (np.ndarray) – array containing a time series of anomaly scores.

  • normal_index (np.ndarray) – boolean values indicating whether an element of anomaly_score is normal or not

Notes

If precision/recall cannot be calculated, the threshold is set to the maximum score.

Returns:

Boolean array which is true for all samples that are either normal and below quantile

or not normal.

Return type:

selection (np.array)