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] historical_forecasts always retrains model #1617

Closed
evanwrm opened this issue Mar 5, 2023 · 1 comment · Fixed by #1619
Closed

[BUG] historical_forecasts always retrains model #1617

evanwrm opened this issue Mar 5, 2023 · 1 comment · Fixed by #1619
Labels
bug Something isn't working triage Issue waiting for triaging

Comments

@evanwrm
Copy link

evanwrm commented Mar 5, 2023

Describe the bug
historical_forecasts always retrains the model ignoring the retrain argument.

To Reproduce
This was likely introduced in #1465. Adding model = self.untrained_model() no longer sets self._fit_called. When evaluating whether to retrain not self._fit_called is always true.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

from darts import TimeSeries
from darts import models
from darts.datasets import AirPassengersDataset

series_air = AirPassengersDataset().load().astype(np.float32)
model = models.LinearRegressionModel(lags=4)

model.historical_forecasts(
    series_air,
    start=0.9,
    retrain=False, # <-- this is ignored
)

Expected behavior
forecasting models to respect the retrain parameter.

System (please complete the following information):

  • Python version: 3.9.16
  • darts version 0.23.1
@evanwrm evanwrm added bug Something isn't working triage Issue waiting for triaging labels Mar 5, 2023
@dennisbader
Copy link
Collaborator

We introduced this in #1465 to avoid mutating the underlying model object.
The model in this case gets retrained because it was not fit before (Darts requires the models to be fit before prediction).
You are right that it is an unexpected behavior that if retrain=False, the model still gets retrained.

We should raise an error when retrain=False and the model was not fit before.

You can avoid the retraining by fitting the model once before calling historical_forecasts()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Issue waiting for triaging
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants