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

Feat/static covs regression #1412

Merged
merged 19 commits into from
Dec 16, 2022
Merged

Conversation

eliane-maalouf
Copy link
Contributor

@eliane-maalouf eliane-maalouf commented Dec 6, 2022

Fixes #1021.

Summary

  • adds static covariates to the features table generated both for fit() and predict().
  • It accomodates for the cases where the static covariates have different dimensions between series in a sequence and to the case where the training series might contain static covs but not the series being used for prediction

Other Information

to test outputs of the function :

import numpy as np
import pandas as pd
from darts import TimeSeries
from sklearn.preprocessing import MinMaxScaler, OneHotEncoder
from darts.dataprocessing.transformers import StaticCovariatesTransformer
from darts.utils import timeseries_generation as tg
from darts.models.forecasting.regression_model import RegressionModel

series = tg.linear_timeseries(length=10)

scaler = StaticCovariatesTransformer(transformer_cat=OneHotEncoder())

static_covs1 = pd.DataFrame(
        data={
            "cont1": [0, 1, 2],
            "cat1": [1, 2, 3],
            "cont2": [0.1, 0.2, 0.3],
            "cat2": ["a", "b", "c"],
        }
    ).astype(dtype={"cat1": "O", "cat2": "O"})
series1 = TimeSeries.from_times_and_values(
        times=series.time_index,
        values=np.concatenate([series.values()] * 3, axis=1),
        columns=["comp1", "comp2", "comp3"],
        static_covariates=static_covs1,
    )
series3 = TimeSeries.from_times_and_values(
        times=series.time_index,
        values=np.concatenate([series.values()*100] * 3, axis=1),
        columns=["comp1", "comp2", "comp3"]
    ) # series without static covs

reg = RegressionModel(lags=3, output_chunk_length=1) 

transformed_series1 = scaler.fit_transform(series1) # one hot encoding of categorical static covs

# check features (dataframe for better visibility) : 
pd.DataFrame(reg._create_lagged_data([transformed_series1, series3], None, None, max_samples_per_ts=5)[0])

@eliane-maalouf eliane-maalouf linked an issue Dec 6, 2022 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Dec 6, 2022

Codecov Report

Base: 93.79% // Head: 93.79% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (2c48c87) compared to base (3e5b5af).
Patch coverage: 96.77% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1412   +/-   ##
=======================================
  Coverage   93.79%   93.79%           
=======================================
  Files          94       94           
  Lines        9408     9425   +17     
=======================================
+ Hits         8824     8840   +16     
- Misses        584      585    +1     
Impacted Files Coverage Δ
darts/utils/data/inference_dataset.py 94.73% <ø> (ø)
darts/models/forecasting/regression_model.py 97.23% <83.33%> (-0.31%) ⬇️
darts/utils/data/tabularization.py 100.00% <100.00%> (ø)
darts/timeseries.py 91.85% <0.00%> (-0.06%) ⬇️
...arts/models/forecasting/torch_forecasting_model.py 89.50% <0.00%> (-0.05%) ⬇️
darts/models/forecasting/block_rnn_model.py 98.24% <0.00%> (-0.04%) ⬇️
darts/models/forecasting/nhits.py 99.27% <0.00%> (-0.01%) ⬇️
darts/datasets/__init__.py 100.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@hrzn hrzn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ! We can merge once the new test is added (and also maybe after we move the new function into tabularization.py).

darts/models/forecasting/regression_model.py Outdated Show resolved Hide resolved
darts/models/forecasting/regression_model.py Outdated Show resolved Hide resolved
@hrzn hrzn marked this pull request as ready for review December 16, 2022 19:27
Copy link
Contributor

@hrzn hrzn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice one @eliane-maalouf !

@eliane-maalouf eliane-maalouf merged commit 9a40ca6 into master Dec 16, 2022
@madtoinou madtoinou deleted the feat/static_covs_regression branch July 5, 2023 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Static covariates in RegressionModels
3 participants