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

How to include scalers as part of the historical forecast method easily #2134

Closed
ETTAN93 opened this issue Dec 27, 2023 · 3 comments
Closed
Labels
feature request Use this label to request a new feature

Comments

@ETTAN93
Copy link

ETTAN93 commented Dec 27, 2023

Hi,

Assuming I have hourly data from 2022-01-01 to 2022-12-31. I want to train on 9 months of data (2022-01-01 to 2022-08-31) and do a historical backtest on the last 3 months of data (2022-09-01 to 2022-12-31). If I retrain every day on the past 90 days of data (retrain = True, stride = 24, train_length = 2160) and have a forecast horizon of 24, i.e. 24 hours, how would I include refitting my scaler as my training set changes for every iteration of the historical forecast method? Is there some sort of params I can call?

Currently, I am initialising my scaler via the method below.

scaler = MinMaxScaler()
target_transformer = Scaler(scaler)
future_cov_transformer = Scaler(scaler)
target_series_fit_scaled = target_transformer.fit_transform(target_series_fit) #target_series_fit contains data from 2022-09-01 to 2022-12-31
future_cov_fit_scaled = future_cov_transformer.fit_transform(future_cov_fit)

target_series_sample_scaled = target_transformer.transform(target_series_sample) #target_series_sample contains data from 2022-09-01 to 2022-12-31
future_cov_sample_scaled = future_cov_transformer.transform(future_cov_sample)

Currently when I do the historical forecast, I first fit the model on target_series_fit_scaled and future_cov_fit_scaled then pass target_series_sample_scaled and future_cov_sample_scaled to the historical forecast method. However, this does not include refitting of the scaler as the training set changes.

model_estimator.fit(
            series = target_series_fit_scaled ,
            future_covariates= future_cov_fit_scaled 
        )

hf_results = model_estimator.historical_forecasts(
      series=target_series_sample_scaled , 
      future_covariates= future_cov_sample_scaled,
      start=2022-09-01, 
      retrain=True,
      forecast_horizon=24,
      stride=24,
      train_length = 2160,
      verbose=True,
      last_points_only=False,
  )
@madtoinou
Copy link
Collaborator

Hi @ETTAN93,

At the moment historical_forecasts/backtest do not accept data transformer and the series is used as is to train the model (with the associated information leakage if the series are scaled), there is no argument to change this.

The feature request is already tracked by #1540 and the PR #2021 started to implement it, I am going to close this issue to limit duplicates.

@madtoinou madtoinou added the feature request Use this label to request a new feature label Dec 27, 2023
@ETTAN93
Copy link
Author

ETTAN93 commented Mar 10, 2024

Hi, I just wanted to check if the feature has already been implemented and is live? I see in the PR that there is still some conflicts so I assume it is not fully completed yet?

@madtoinou
Copy link
Collaborator

The feature is not yet implemented, it will be when the PR is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Use this label to request a new feature
Projects
None yet
Development

No branches or pull requests

2 participants