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

Odd Behaviour with new dictionary format to define lags #2062

Closed
ETTAN93 opened this issue Nov 9, 2023 · 5 comments
Closed

Odd Behaviour with new dictionary format to define lags #2062

ETTAN93 opened this issue Nov 9, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@ETTAN93
Copy link

ETTAN93 commented Nov 9, 2023

I am trying out the new dict format to define lags in the latest version of darts: 0.26.0

However, there seems to be some odd behaviour which I can't figure out why:

The way I define my covariates and the data:
image

The way the model and lags are initialized:
image

The way historical forecast is run:
image

This works completely fine when I define the lags in this way.

However, when I take out any features from the dataset as well the lags, e.g.
image
image

I get an error:
image

@ETTAN93 ETTAN93 added bug Something isn't working triage Issue waiting for triaging labels Nov 9, 2023
@dennisbader
Copy link
Collaborator

Hi @ETTAN93, can you provide a minimal reproducible example that we can run to reproduce the bug (e.g. not a picture, and code to recreate the time series, you can use TimeSeries.from_times_and_values() to generate some example series)?

Also, we might have fixed this bug in #2040 that resolved a similar issue.

@ETTAN93
Copy link
Author

ETTAN93 commented Nov 9, 2023

@dennisbader, from the example in #2040, it does seem like that is a similar error to what I was experiencing.

Do you know when will the fix be available for use?

@dennisbader
Copy link
Collaborator

Yes, we aim to release within the next 1-2 weeks.

@ETTAN93
Copy link
Author

ETTAN93 commented Nov 9, 2023

@dennisbader Please see below the code example of my reproduced error. Seems like it is not taking into account the future cov lags at 0 when it is calculating the number of features X is providing

import pandas as pd
import numpy as np
from darts import TimeSeries
from darts.models import LinearRegressionModel

dates = pd.date_range(start='2020-08-30 10:00:00', end='2020-09-01 11:00:00', freq='1H')

feature_1 = np.random.randint(1,10,50)
feature_2 = np.random.randint(1,10,50)
feature_3 = np.random.randint(1,10,50)
target = np.random.randint(1,10,50)

data_df = pd.DataFrame({'feature1': feature_1, 
                        'feature2': feature_2, 
                        'feature3': feature_3, 
                        'target': target}, index = dates)

target_series = TimeSeries.from_dataframe(data_df[['target']])
future_cov_series = TimeSeries.from_dataframe(data_df[['feature1', 'feature2', 'feature3']])

start_date = pd.Timestamp("2020-08-30 10:00:00")
split_date = pd.Timestamp("2020-08-31 20:00:00") 
end_date = pd.Timestamp("2020-09-01 11:00:00")
test_set_start_date =  split_date + relativedelta(hours = 1)

target_series_sample = target_series.slice(start_date, end_date)
future_cov_sample = future_cov_series.slice(start_date, end_date)
target_series_fit = target_series.slice(start_date, split_date)
future_cov_fit = future_cov_series.slice(start_date, split_date)

lr_model = LinearRegressionModel(
    lags = [-1],
    lags_future_covariates= {
        'feature1': [-2, -1, 0], 
        'feature2': [-1, 0], 
        'feature3': [-3, -2, -1, 0], 
    },
    lags_past_covariates=None,
    output_chunk_length = 24,
    n_jobs=-1,
    random_state=42,
    multi_models=True
)

lr_model.fit(
    series = target_series_fit,
    future_covariates = future_cov_fit,
)

hf_results = lr_model.historical_forecasts(
    series = target_series_sample, 
    past_covariates = None,
    future_covariates = future_cov_sample,
    start = test_set_start_date, 
    retrain = False,
    forecast_horizon = 2,
    stride = 1,
    train_length = None,
    verbose = True,
    last_points_only = False,
)

Error message:
image

@madtoinou madtoinou removed the triage Issue waiting for triaging label Nov 10, 2023
@madtoinou
Copy link
Collaborator

I just checked on the master branch, #2040 indeed fixes this problem and will be part of the next release.

Closing this issue, don't hesitate to reopen if it persists after updating darts to the latest version after the release.

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
None yet
Development

No branches or pull requests

3 participants