I am trying to create a pipeline in Python which automatically identifies global and contextual anomalies of a time series.
Which one of these approaches do you believe is more correct?
Method 1)
- Detect global outliers using z-score threshold.
- Remove the outliers from the time series and impute values
- Detect if seasonality/periodicity is present
- If yes on 3) perform seasonal decomposition
- Detect contextual outliers using z-score threshold on residuals.
- Combine both groups of outliers.
Method 2)
- Detect global outliers using z-score threshold.
- Remove the outliers from the time series and impute values
- Detect if seasonality/periodicity is present
- If yes on 3) perform seasonal decomposition
- Remove seasonality and trend from original signal potentially containing global outliers as well
- Detect contextual outliers and global outliers using z-score threshold on residuals.
Method 3)
Something else which you know of?
Appreciate any insights or tips!