Package: pyadts
Anomaly Detection for Time-series (PyADTS)PyADTSis aimed at accelerating the workflow of time series anomaly detection for researchers. It contains various utilities for data loading, pre-processing, detector construction, detector ensemble, evaluation and etc.PyADTScan help you to write less boilerplate on following parts:Preparing dataset & pre-processingFeature extraction (Optional)Model trainingEnsemble (Optional)EvaluationYou can find the completedocumentationhere.Table of Contents:Anomaly Detection for Time-series (PyADT)InstallationQuick StartOther UtilitiesImplemented AlgorithmsInstallationTo install the package locally, run:cd<pyadt_dir>
pipinstall.Quick StartFetch the datasetPyADTcontains various built-in datasets. To utilize them:fromsrc.pyadts.dataimportget_nab_nyc_taxidata=get_nab_nyc_taxi(root_path='<the_path_of_nab_dataset>')All components of the dataset are organized as a dict:{'value': value, 'label': label, 'timestamp': timestamp, 'datetime': datetime}Pre-processingIt's important to pre-process the time series before training.PyADToffered three types of pre-processing methods including:Rearrangement: Sort the values along with the timestamp and reconstruct the timestamp to discover missing values. (return a dict and append an attributemissing)Normalization: Normalize the time seriesImputation: Impute the time series.fromsrc.pyadts.dataimportseries_impute,series_normalize,series_rearrangedata_processed=series_rearrange(**data)data_processed['value']=series_normalize(data_processed['value'],mask=data_processed['missing'],method='zscore')data_processed['value']=series_impute(data_processed['value'],missing=data_processed['missing'],method='linear')Feature extractionExtracting manual features is essential for some anomaly detection approaches.PyADToffered various options for extracting features including:Simple features: logarithm, difference, second-order difference, ...Window-based features: window mean value, window std value, ...Decomposition features: STL decomposition, ...Frequency domain features: wavelet features, spectral residual, ...Regression features: SARIMA regression residual, Exponential Smoothing residual, ...fromsrc.pyadts.dataimportFeatureExtractorfeature_extractor=FeatureExtractor()Train the modelDifferent anomaly detection algorithms should be utilized to tackle different scenarios.PyADTcontains various algorithms including supervised-, unsupervised-, nonparametric-methods (you can refer the full list ofimplemented algorithms).fromsrc.pyadtsimportThresholdDetectortrain_x=data['value']detector=ThresholdDetector()pred_y=detector.fit_predict(train_x)EnsembleTODOEvaluationIt's easy to evaluate your algorithms usingPyADT's built-in metrics:fromsrc.pyadtsimportroc_auctrain_y=data['label']roc=roc_auc(pred_y,train_y,delay=7)In real-world applications, the delay of anomaly alerts is acceptable. SoPyADToffered thedelayargument for all metrics.The pipelineTODOOther UtilitiesVisualizationYou can visualize your data with a single line of code:fromsrc.pyadts.dataimportplot_seriesfig=plot_series(value=data['value'],label=data['label'],datetime=data['datetime'],plot_vline=True)fig.show()The example visualization:Generate synthetic dataTODOImplemented AlgorithmsSupervised ApproachesRandom ForestSVMDeep Neural NetworkUnsupervised ApproachesNon-parametricSRThresholdQuantileK​-SigmaStatistic-basedSPOTDSPOTAutoregressionESDS-ESDS-H-ESDMachine learning-basedLOFIsolation ForestOCSVMDeep-basedAutoencoderRNN AutoencoderDonutTODOFix bugs and reformat codeComplete the modelsIncorporating NumbaImplement the pipelineSynthetic data generator