Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Error on using DifferencingTransform in AutoRegressivePipeline #267

Open
1 task done
d-a-bunin opened this issue Mar 7, 2024 · 1 comment
Open
1 task done
Labels
bug Something isn't working

Comments

@d-a-bunin
Copy link
Collaborator

d-a-bunin commented Mar 7, 2024

🐛 Bug Report

Error on using DifferencingTransform in AutoRegressivePipeline:

ValueError: Test should go after the train without gaps

Some users also told that in similar scenarios they saw error like:

ValueError: Inverse transform can be applied only to full train or test that should be in the future

Expected behavior

No error. Or at least understand the reason of the error and how to avoid it.

How To Reproduce

from loguru import logger

from etna.pipeline import AutoRegressivePipeline
from etna.models import CatBoostMultiSegmentModel
from etna.transforms import DifferencingTransform
from etna.transforms import DateFlagsTransform
from etna.metrics import MAE


def generate_ts():
    import numpy as np
    from etna.datasets import TSDataset
    from etna.datasets import generate_ar_df

    df = generate_ar_df(
        start_time="2020-01-01",
        periods=100,
        n_segments=10,
        freq="D",
        random_seed=0,
    )

    # make strictly positive
    df["target"] = np.abs(df["target"]) + 1

    df_wide = TSDataset.to_dataset(df)
    ts = TSDataset(df=df_wide, freq="D")
    return ts


def main():
    ts = generate_ts()

    transforms = [
        DateFlagsTransform(),
        DifferencingTransform(in_column="target", inplace=True)
    ]
    model = CatBoostMultiSegmentModel()
    pipeline = AutoRegressivePipeline(model=model, transforms=transforms, horizon=7)

    logger.info("Running backtest")
    metrics = [MAE()]
    _ = pipeline.backtest(ts=ts, metrics=metrics, n_folds=3, n_jobs=1)


if __name__ == "__main__":
    main()

Environment

No response

Additional context

No response

Checklist

  • Bug appears at the latest library version
@d-a-bunin d-a-bunin added the bug Something isn't working label Mar 7, 2024
@d-a-bunin d-a-bunin moved this from New to Todo in etna board Mar 7, 2024
@d-a-bunin
Copy link
Collaborator Author

It seems like the problem is in the core logic of AutoRegressivePipeline and requirements of DifferencingTransform.

DifferencingTransform requires the data in inverse_transform to always go right after the data that it saw during fit. Otherwise, it can't reconstruct the data because it doesn't know data point that goes before data we are inverse transforming.

In AutoRegressivePipeline we make fit on training data like in Pipeline and doesn't refit it during forecasting, so DifferencingTransform fits only on training data. During forecasting AutoRegressivePipeline forecasts step steps ahead every iteration and at the end of the iteration it calls inverse_transform on forecasted piece. On the second iteration this piece goes after train with gap of size step, and, as a result, DifferencingTransform fails.

I currently doesn't know any obvious way to solve this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

1 participant