alibi_detect.od.sklearn.base module

class alibi_detect.od.sklearn.base.FitMixinSklearn[source]

Bases: ABC

check_fitted()[source]

Checks to make sure object has been fitted.

Raises:

NotFittedError – Raised if method called and object has not been fit.

abstract fit(x_ref)[source]

Abstract fit method.

Parameters:

xtorch.Tensor to fit object on.

Return type:

Self

fitted = False
class alibi_detect.od.sklearn.base.SklearnOutlierDetector[source]

Bases: FitMixinSklearn, ABC

Base class for sklearn backend outlier detection algorithms.

__call__(x)[source]

Classify outliers.

Parameters:

x (ndarray) – Data to classify.

Return type:

ndarray

check_threshold_inferred()[source]

Check if threshold is inferred.

Raises:

ThresholdNotInferredError – Raised if threshold is not inferred.

infer_threshold(x, fpr)[source]

Infer the threshold for the data. Prerequisite for outlier predictions.

Parameters:
  • x (ndarray) – Data to infer the threshold for.

  • fpr (float) – False positive rate to use for threshold inference.

Raises:
  • ValueError – Raised if fpr is not in (0, 1).

  • ValueError – Raised if fpr is less than 1/len(x).

Return type:

None

predict(x)[source]

Predict outlier labels for the data.

Computes the outlier scores. If the detector is not fit on reference data we raise an error. If the threshold is inferred, the outlier labels and p-values are also computed and returned. Otherwise, the outlier labels and p-values are set to None.

Parameters:

x (ndarray) – Data to predict.

Return type:

SklearnOutlierDetectorOutput

Returns:

SklearnOutlierDetectorOutput – Output of the outlier detector.

Raises:

ValueError – Raised if the detector is not fit on reference data.

abstract score(x)[source]

Score the data.

Parameters:

x (ndarray) – Data to score.

Return type:

ndarray

threshold = None
threshold_inferred = False
class alibi_detect.od.sklearn.base.SklearnOutlierDetectorOutput(threshold_inferred, instance_score, threshold, is_outlier, p_value)[source]

Bases: object

Output of the outlier detector.

instance_score: ndarray
is_outlier: ndarray | None
p_value: ndarray | None
threshold: ndarray | None
threshold_inferred: bool