Skip to content

Commit

Permalink
Made .fit() handle KeyboardInterrupt gracefully (#96)
Browse files Browse the repository at this point in the history
This allows user to prematurely interrupt an ongoing .fit() without losing all
the progress.
  • Loading branch information
IDex authored and bjkomer committed Feb 19, 2018
1 parent 4b28c67 commit b880877
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions hpsklearn/estimator.py
Expand Up @@ -741,13 +741,16 @@ def fit(self, X, y, EX_list=None,
adjusted_max_evals = (self.max_evals if not warm_start else
len(self.trials.trials) + self.max_evals)
while len(self.trials.trials) < adjusted_max_evals:
increment = min(self.fit_increment,
adjusted_max_evals - len(self.trials.trials))
fit_iter.send(increment)
if filename is not None:
with open(filename, 'wb') as dump_file:
self.info('---> dumping trials to', filename)
pickle.dump(self.trials, dump_file)
try:
increment = min(self.fit_increment,
adjusted_max_evals - len(self.trials.trials))
fit_iter.send(increment)
if filename is not None:
with open(filename, 'wb') as dump_file:
self.info('---> dumping trials to', filename)
pickle.dump(self.trials, dump_file)
except KeyboardInterrupt:
break

self.retrain_best_model_on_full_data(X, y, EX_list, weights)

Expand Down

0 comments on commit b880877

Please sign in to comment.