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

Fix/bug in ensemble models to support underlying stochastic models #1423

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions darts/models/forecasting/ensemble_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,6 @@ def ensemble(
@property
def min_train_series_length(self) -> int:
return max(model.min_train_series_length for model in self.models)

def _is_probabilistic(self) -> bool:
return all([model._is_probabilistic() for model in self.models])
3 changes: 3 additions & 0 deletions darts/models/forecasting/theta.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ def min_train_series_length(self) -> int:
else:
return 3

def _is_probabilistic(self) -> bool:
eliane-maalouf marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

this one can be removed as well :) after that all looks good!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

;) missed this one, thanks

return False


class FourTheta(LocalForecastingModel):
def __init__(
Expand Down
13 changes: 13 additions & 0 deletions darts/tests/models/forecasting/test_ensemble_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
NaiveDrift,
NaiveEnsembleModel,
NaiveSeasonal,
RegressionEnsembleModel,
Theta,
)
from darts.tests.base_test_class import DartsBaseTestClass
Expand Down Expand Up @@ -83,6 +84,18 @@ def test_predict_ensemble_local_models(self):
np.array_equal(forecast_naive_ensemble.values(), forecast_mean.values())
)

def test_stochastic_ensemble(self):
model1 = LinearRegressionModel(lags=1, likelihood="quantile")
model2 = LinearRegressionModel(lags=2, likelihood="quantile")

naive_ensemble = NaiveEnsembleModel([model1, model2])
self.assertTrue(naive_ensemble._is_probabilistic())

regression_ensemble = RegressionEnsembleModel(
[model1, model2], regression_train_n_points=1
)
self.assertTrue(regression_ensemble._is_probabilistic())

@unittest.skipUnless(TORCH_AVAILABLE, "requires torch")
def test_input_models_global_models(self):
NaiveEnsembleModel([RNNModel(12), TCNModel(10, 2), NBEATSModel(10, 2)])
Expand Down