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
Preprocessorobject or a list ofPreprocessorobjects. This list is converted into aChainedPreprocessor. At the moment the Pipeline always requires a Preprocessor object passed at construction. If no preprocessing is desired, you need to explicitly pass anIdentitypreprocessor.- 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:
- 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
PreprocessorandBaseDetectorare combined into aPipelineobject.- 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_test: ndarray, y_test: ndarray, X_train: ndarray, y_train: ndarray | None) Dict[str, float][source]
Run the pipeline and evaluate performance. The pipeline will be trained on the given train data (potentially without labels) and performance will be estimated on the test data.
- Parameters:
X_test (array-like of shape (n_samples_test, n_attributes)) – The test time series data.
y_test (array-like of shape (n_samples_test)) – The ground truth anomaly labels of the test data.
X_train (array-like of shape (n_samples_train, n_attributes)) – The train time series data.
y_train (array-like of shape (n_samples_train) or
None.) – The ground truth anomaly labels of the train data. Note that, even thoughy_traincan beNone, it must be provided.
- Returns:
performances – The evaluation of the performance metrics. The keys are string descriptors of the performance metrics, with values the corresponding performance score.
- Return type:
Dict[str, float]