Skip to content

Commit 61a1cd3

Browse files
ahn1340mfeurer
authored andcommitted
Raise error if ensemble is not built (#480)
* . * . * AutoSklearnClassifier/Regressor's fit, refit, fit_ensemble now return self. * Initial commit. Work in Progress. * Fix minor printing error in sprint_statistics. * Revert "Fix#460" * Resolve rebase conflict * combined unittests to reduce travis runtime * . * . * . * . * .
1 parent 013a273 commit 61a1cd3

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

autosklearn/automl.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,13 @@ def _fit(self, datamanager, metric, only_return_configuration_space=False):
389389
self._logger.info(
390390
'Start Ensemble with %5.2fsec time left' % time_left_for_ensembles)
391391
if time_left_for_ensembles <= 0:
392-
self._logger.warning("Not starting ensemble builder because there "
393-
"is no time left!")
394392
self._proc_ensemble = None
393+
# Fit only raises error when ensemble_size is not zero but
394+
# time_left_for_ensembles is zero.
395+
if self._ensemble_size > 0:
396+
raise ValueError("Not starting ensemble builder because there "
397+
"is no time left. Try increasing the value "
398+
"of time_left_for_this_task.")
395399
else:
396400
self._proc_ensemble = self._get_ensemble_process(time_left_for_ensembles)
397401
if self._ensemble_size > 0:
@@ -487,11 +491,15 @@ def send_warnings_to_log(message, category, filename, lineno,
487491

488492
if self._keep_models is not True:
489493
raise ValueError(
490-
"Predict can only be called if 'keep_models==True'")
494+
"Refit can only be called if 'keep_models==True'")
491495
if self.models_ is None or len(self.models_) == 0 or \
492496
self.ensemble_ is None:
493497
self._load_models()
494498

499+
# Refit is not applicable when ensemble_size is set to zero.
500+
if self.ensemble_ is None:
501+
raise ValueError("Refit can only be called if 'ensemble_size != 0'")
502+
495503
random_state = np.random.RandomState(self._seed)
496504
for identifier in self.models_:
497505
if identifier in self.ensemble_.get_selected_model_identifiers():
@@ -550,6 +558,13 @@ def predict(self, X, batch_size=None, n_jobs=1):
550558
self.ensemble_ is None:
551559
self._load_models()
552560

561+
# If self.ensemble_ is None, it means that ensemble_size is set to zero.
562+
# In such cases, raise error because predict and predict_proba cannot
563+
# be called.
564+
if self.ensemble_ is None:
565+
raise ValueError("Predict and predict_proba can only be called "
566+
"if 'ensemble_size != 0'")
567+
553568
# Parallelize predictions across models with n_jobs processes.
554569
# Each process computes predictions in chunks of batch_size rows.
555570
all_predictions = joblib.Parallel(n_jobs=n_jobs)(
@@ -655,10 +670,10 @@ def _load_models(self):
655670
['partial-cv', 'partial-cv-iterative-fit']:
656671
raise ValueError('No models fitted!')
657672

658-
self.models = []
673+
self.models_ = []
659674

660675
else:
661-
self.models = []
676+
self.models_ = []
662677

663678
def score(self, X, y):
664679
# fix: Consider only index 1 of second dimension

0 commit comments

Comments
 (0)