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

added check for untrained models for copying of model parameters #728

Merged
merged 2 commits into from
Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions darts/models/forecasting/ensemble_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def __init__(self, models: Union[List[ForecastingModel], List[GlobalForecastingM
raise_if_not(is_local_ensemble or self.is_global_ensemble,
"All models must either be GlobalForecastingModel instances, or none of them should be.",
logger)

raise_if(any([m._fit_called for m in models]),
"Cannot instantiate EnsembleModel with trained/fitted models. "
"Consider resetting all models with `my_model.untrained_model()`",
logger)

super().__init__()
self.models = models
self.is_single_series = None
Expand Down
9 changes: 9 additions & 0 deletions darts/tests/models/forecasting/test_ensemble_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ class EnsembleModelsTestCase(DartsBaseTestClass):
seq1 = [_make_ts(0), _make_ts(10), _make_ts(20)]
cov1 = [_make_ts(5), _make_ts(15), _make_ts(25)]

def test_untrained_models(self):
model = NaiveDrift()
_ = NaiveEnsembleModel([model])

# trained models should raise error
model.fit(self.series1)
with self.assertRaises(ValueError):
NaiveEnsembleModel([model])

def test_input_models_local_models(self):
with self.assertRaises(ValueError):
NaiveEnsembleModel([])
Expand Down