Skip to content

[BUG] Check pytorch-forecasting models with freq > "1D" #452

Closed
1 task done
martins0n opened this issue Jan 13, 2022 · 1 comment · Fixed by #463
Closed
1 task done

[BUG] Check pytorch-forecasting models with freq > "1D" #452

martins0n opened this issue Jan 13, 2022 · 1 comment · Fixed by #463
Assignees
Labels
bug Something isn't working
Milestone

Comments

@martins0n
Copy link
Contributor

🐛 Bug Report

PytorchForecastingTransform._calculate_freq_unit not work correctly with 'MS' freq for example

Expected behavior

It should work correctly for any defualt pandas frequency.

How To Reproduce

import pandas as pd

from etna.datasets.tsdataset import TSDataset
from etna.pipeline import Pipeline
from etna.transforms import DateFlagsTransform
from etna.transforms import LagTransform
from etna.metrics import SMAPE
from etna.transforms import PytorchForecastingTransform
from pytorch_forecasting.data import GroupNormalizer
from etna.models.nn import DeepARModel
from datetime import datetime

import warnings

current_time_start = datetime.now().time()
original_df = pd.read_csv(
    "examples/data/example_dataset.csv", sep=','
)

print(original_df)
df = TSDataset.to_dataset(original_df)
df.index = pd.Index(pd.date_range("2021-01-01", freq="MS", periods=len(df)), name="timestamp")

ts = TSDataset(df, freq="MS")

print(ts)

HORIZON = 1

transform_date = DateFlagsTransform(month_number_in_year=True, day_number_in_week=False, day_number_in_month=False, out_column="regressor_dateflag")
num_lags = 10
transform_lag = LagTransform(in_column="target", lags=[HORIZON+i for i in range(num_lags)], out_column="regressor_target_lag")
lag_columns = [f"regressor_target_lag_{HORIZON+i}" for i in range(num_lags)]

transform_deepar = PytorchForecastingTransform(
    max_encoder_length=HORIZON,
    max_prediction_length=HORIZON,
    time_varying_known_reals=["time_idx"]+lag_columns,
    time_varying_unknown_reals=["target"],
    time_varying_known_categoricals=["regressor_dateflag_month_number_in_year"],
    target_normalizer=GroupNormalizer(groups=["segment"]),
)

model_deepar = DeepARModel(max_epochs=3, learning_rate=[0.01], gpus=0, batch_size=64)
metrics = [SMAPE()]

pipeline_deepar = Pipeline(
    model=model_deepar,
    horizon=HORIZON,
    transforms=[transform_lag, transform_date, transform_deepar]
)

# metrics_deepar, forecast_deepar, fold_info_deepar = pipeline_deepar.backtest(ts, metrics=metrics, n_folds=3, n_jobs=1)
pipeline_deepar.fit(ts=ts)

forecasted = pipeline_deepar.forecast()
print(forecasted)

Environment

No response

Additional context

No response

Checklist

  • Bug appears at the latest library version
@martins0n martins0n added the bug Something isn't working label Jan 13, 2022
@martins0n
Copy link
Contributor Author

Possible workaround -- to change timestamp index with dummy timestamp index with daily frequency

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant