Pipeline module

This module contains functionality to combine preprocessing, anomaly detection, and evaluation in a single wrapped object.

>>> from dtaianomaly import pipeline

Users are not expected to extend the base Pipeline objects as they are wrappers of underlying dtaianomaly objects. Custom functionality is better achieved by implementing the dtaianomaly.preprocessing.Preprocessor, dtaianomaly.anomaly_detection.BaseDetector or dtaianomaly.evaluation.Metric objects.

class dtaianomaly.pipeline.Pipeline(preprocessor: Preprocessor | List[Preprocessor], detector: BaseDetector)[source]

Pipeline to combine preprocessing and anomaly detection

The pipeline works with a single Preprocessor object or a list of Preprocessor objects. This list is converted into a ChainedPreprocessor. At the moment the Pipeline always requires a Preprocessor object passed at construction. If no preprocessing is desired, you need to explicitly pass an Identity preprocessor.

Parameters:
  • preprocessor (Preprocessor or list of Preprocessors) – The preprocessors to include in this pipeline.

  • detector (BaseDetector) – The anomaly detector to include in this pipeline.

decision_function(X: ndarray) ndarray[source]

Compute raw anomaly scores.

Note that depending on the preprocessor this output might not have the same shape as the input.

Parameters:

X (array-like of shape (n_samples, n_attributes)) – Raw time series

Returns:

anomaly_scores – The predicted anomaly scores

Return type:

array-like of shape (n_samples)

fit(X: ndarray, y: ndarray | None = None) Pipeline[source]

Fit this pipeline to the given data.

Parameters:
  • X (array-like of shape (n_samples, n_attributes)) – Input time series.

  • y (array-like of shape (n_samples)) – The ground truth labels, passed to the preprocessor and detector.

Returns:

self – Returns the instance itself

Return type:

Pipeline

class dtaianomaly.pipeline.EvaluationPipeline(preprocessor: Preprocessor | List[Preprocessor], detector: BaseDetector, metrics: ProbaMetric | List[ProbaMetric])[source]

Pipeline to combine a base pipeline, and a set of metrics. Used in the workflow. The given Preprocessor and BaseDetector are combined into a Pipeline object.

Parameters:
  • preprocessor (Preprocessor or list of Preprocessors) – The preprocessors to include in this evaluation pipeline.

  • detector (BaseDetector) – The anomaly detector to include in this evaluation pipeline.

  • metrics (list of Probametric objects) – The evaluation metrics to compute in this evaluation pipeline.

run(X: ndarray, y: ndarray) Dict[str, float][source]

Run the pipeline and evaluate performance.

Parameters:
X: array-like of shape (n_samples, n_attributes)

Input time series.

y: array-like of shape (n_samples)

The ground truth labels.

:returns: **performances – The evaluation of the performance metrics. The keys are**

string descriptors of the performance metrics, with values the corresponding performance score.

:rtype: Dict[str, float]