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/multivariate on baseline models #1373

Merged
merged 13 commits into from
Nov 28, 2022

Conversation

BlazejNowicki
Copy link
Contributor

Fixes #639

Summary

Extend baseline models to support multivariate time series.

Other Information

New class LocalMultivaraiteForecastingModel was added to differentiate 'local' models that can be trained on both uni- and multivariate time series.

@@ -35,16 +36,15 @@ def __str__(self):

def fit(self, series: TimeSeries):
super().fit(series)
self.mean_val = np.mean(series.univariate_values())
self.mean_val = np.mean(series.values(), axis=0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.mean_val = np.mean(series.values(), axis=0)
self.mean_val = np.mean(series.values(copy=False), axis=0)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking we may want to test that the series is deterministic (has only one sample) in all these models.

Copy link
Contributor Author

@BlazejNowicki BlazejNowicki Nov 22, 2022

Choose a reason for hiding this comment

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

I think it's done in the ForecastingModel.
Good point. I misinterpreted "deterministic" at first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put a check in LocalForecastingModel class.

darts/models/forecasting/baselines.py Outdated Show resolved Hide resolved
darts/models/forecasting/baselines.py Outdated Show resolved Hide resolved
darts/models/forecasting/forecasting_model.py Show resolved Hide resolved
darts/models/forecasting/forecasting_model.py Show resolved Hide resolved
@@ -1403,7 +1409,7 @@ def _get_encoders_n(self, n) -> int:
return n


class FutureCovariatesLocalForecastingModel(LocalForecastingModel, ABC):
class FutureCovariatesLocalForecastingModel(LocalMultivariateForecastingModel, ABC):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like this class structure too much, because it means that local future covariates models must necessarily support multivariate series. Whereas we could in principles have some future covariates models working on univariate series only (although we maybe don't have any at the moment).

I think this one should still inherit from LocalForecastingModel only, WDYT?
Also a cleaner approach might be to rethink most of our model super-classes and see them as "mix-in interfaces" more. But that would be beyond the scope of this PR :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about the mixin approach but it seemed out of scope. I thought that requiring support for multivariate series was ok because that's how it was done previously. By default all models that inherit from LocalForecastingModel were checked if they are fitted on univariate time series with explicit if statement that excluded FutureCovaraitesLocalForecastingModel. The only difference with this approach is that I don't exclude that specific class but all models that are in LocalMultivaraiteForecastingModel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the end I put checks directly in the models that don't support multivariate input. It is probably the most versatile solution because it can be changed per model basis and it doesn't unnecessarily increase complexity of class structure.

@codecov-commenter
Copy link

codecov-commenter commented Nov 23, 2022

Codecov Report

Base: 94.03% // Head: 93.96% // Decreases project coverage by -0.06% ⚠️

Coverage data is based on head (f9cf2c7) compared to base (281217a).
Patch coverage: 90.90% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1373      +/-   ##
==========================================
- Coverage   94.03%   93.96%   -0.07%     
==========================================
  Files          82       82              
  Lines        8905     8905              
==========================================
- Hits         8374     8368       -6     
- Misses        531      537       +6     
Impacted Files Coverage Δ
darts/models/forecasting/baselines.py 88.15% <60.00%> (+0.15%) ⬆️
darts/models/forecasting/arima.py 95.34% <100.00%> (+0.11%) ⬆️
darts/models/forecasting/auto_arima.py 100.00% <100.00%> (ø)
darts/models/forecasting/croston.py 92.50% <100.00%> (ø)
darts/models/forecasting/exponential_smoothing.py 100.00% <100.00%> (ø)
darts/models/forecasting/fft.py 96.19% <100.00%> (+0.03%) ⬆️
darts/models/forecasting/forecasting_model.py 97.05% <100.00%> (+0.03%) ⬆️
darts/models/forecasting/prophet_model.py 94.28% <100.00%> (+0.04%) ⬆️
darts/models/forecasting/sf_auto_arima.py 91.17% <100.00%> (ø)
darts/models/forecasting/sf_ets.py 100.00% <100.00%> (ø)
... and 6 more

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. Thanks!

@BlazejNowicki BlazejNowicki merged commit 151db2d into master Nov 28, 2022
@madtoinou madtoinou deleted the feat/multivariate-on-baseline-models 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.

Extend baseline models to support multivariate time series
3 participants