etna-team / etna

ETNA – Time-Series Library
https://docs.etna.ai
Apache License 2.0
142 stars 7 forks source link

Transform for series decomposition using ETNA models #411

Closed brsnw250 closed 3 months ago

brsnw250 commented 4 months ago

🚀 Task description

In some scenarios, we might be interested in estimating the series decomposition using components from a particular model. One of such scenarios is anomaly detection. This task proposes a new transform ModelDecomposeTransform, that will provide the ability of series decomposition in the pipeline.

Plan

Proposed transform should work only with in-sample data.

Implement the following interface:

class ModelDecomposeTransform(IrreversibleTransform):
    def __init__(self, model: AbstractModel, in_column: str = "target", residuals: bool = False):
        pass

    def get_regressors_info(self) -> List[str]:
        return []

    def _fit(self, df: pd.DataFrame):
        pass

    def _transform(self, df: pd.DataFrame) -> pd.DataFrame:
        pass

    def fit(self, ts: TSDataset) -> "ModelDecomposeTransform":
        pass

    def transform(self, ts: TSDataset) -> TSDataset:
        pass
  1. __init__ - check inintial conditions and initialize object.
    • model - model, that will be used for estimation decomposition
    • in_column - which column will be used for decomposition
    • residuals - whether to add column with residuals (e.g. target - sum(components))
  2. get_regressors_info - return empty list, since transfrom doesn't produce any
  3. fit - save timestamp bounds for the training data and fit the model
  4. transform:
    • run timestamp checks to determine if in-sample data being transform, use paddding with nan for timestamps in future
    • use fitted model to estimate decomposition for selected column
    • estimate residuals if necesary
    • add decomposition to the dataset

Test cases

  1. Test in-sample and out-of-sample cases
  2. Add tests similar to other transforms (inference test, etc.).
  3. Test that the transform works with different models (Holt-Winters, CatBoost, Prophet, SARIMAX)
  4. Test that transform works in the pipeline with other transforms (especially with IForestOutlierTransform)
  5. Ensure decomposition is not corrupted or lost after calling (pipelin.forecast, pipeline.predict with components and intervals)
  6. Ensure backtest works as expected

Additional context

No response