hyperopt / hyperopt-sklearn

Hyper-parameter optimization for sklearn
hyperopt.github.io/hyperopt-sklearn
Other
1.58k stars 271 forks source link

Error running demo iris notebook - Iteration of zero-sized operands is not enabled #60

Closed naoko closed 7 years ago

naoko commented 7 years ago

I was trying to follow demo notebook published here: http://nbviewer.jupyter.org/github/hyperopt/hyperopt-sklearn/blob/master/notebooks/Demo-Iris.ipynb but I'm getting the following error on cell # 4. I tried to run just estimator.fit(X_train,y_train) after cell #3 execution but I'm getting the same error. Any insight would be appreciated.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-28-b2e0025bc20c> in <module>()
      5                                                 mintodate_ylim=(-.01, .05))
      6 while len(estimator.trials.trials) < estimator.max_evals:
----> 7     fit_iterator.send(1) # -- try one more model
      8     plot_helper.post_iter()
      9 plot_helper.post_loop()

/Users/nreeves/projects/automl/env/lib/python2.7/site-packages/hpsklearn/estimator.pyc in fit_iter(self, X, y, EX_list, valid_size, n_folds, cv_shuffle, warm_start, random_state, weights, increment)
    614                               #    so we notice them.
    615                               catch_eval_exceptions=False,
--> 616                               return_argmin=False, # -- in case no success so far
    617                              )
    618             else:

/Users/nreeves/projects/automl/env/lib/python2.7/site-packages/hyperopt/fmin.pyc in fmin(fn, space, algo, max_evals, trials, rstate, allow_trials_fmin, pass_expr_memo_ctrl, catch_eval_exceptions, verbose, return_argmin)
    305             verbose=verbose,
    306             catch_eval_exceptions=catch_eval_exceptions,
--> 307             return_argmin=return_argmin,
    308         )
    309 

/Users/nreeves/projects/automl/env/lib/python2.7/site-packages/hyperopt/base.pyc in fmin(self, fn, space, algo, max_evals, rstate, verbose, pass_expr_memo_ctrl, catch_eval_exceptions, return_argmin)
    633             pass_expr_memo_ctrl=pass_expr_memo_ctrl,
    634             catch_eval_exceptions=catch_eval_exceptions,
--> 635             return_argmin=return_argmin)
    636 
    637 

/Users/nreeves/projects/automl/env/lib/python2.7/site-packages/hyperopt/fmin.pyc in fmin(fn, space, algo, max_evals, trials, rstate, allow_trials_fmin, pass_expr_memo_ctrl, catch_eval_exceptions, verbose, return_argmin)
    318                     verbose=verbose)
    319     rval.catch_eval_exceptions = catch_eval_exceptions
--> 320     rval.exhaust()
    321     if return_argmin:
    322         return trials.argmin

/Users/nreeves/projects/automl/env/lib/python2.7/site-packages/hyperopt/fmin.pyc in exhaust(self)
    197     def exhaust(self):
    198         n_done = len(self.trials)
--> 199         self.run(self.max_evals - n_done, block_until_done=self.async)
    200         self.trials.refresh()
    201         return self

/Users/nreeves/projects/automl/env/lib/python2.7/site-packages/hyperopt/fmin.pyc in run(self, N, block_until_done)
    171             else:
    172                 # -- loop over trials and do the jobs directly
--> 173                 self.serial_evaluate()
    174 
    175             if stopped:

/Users/nreeves/projects/automl/env/lib/python2.7/site-packages/hyperopt/fmin.pyc in serial_evaluate(self, N)
     90                 ctrl = base.Ctrl(self.trials, current_trial=trial)
     91                 try:
---> 92                     result = self.domain.evaluate(spec, ctrl)
     93                 except Exception as e:
     94                     logger.info('job exception: %s' % str(e))

/Users/nreeves/projects/automl/env/lib/python2.7/site-packages/hyperopt/base.pyc in evaluate(self, config, ctrl, attach_attachments)
    838                 memo=memo,
    839                 print_node_on_error=self.rec_eval_print_node_on_error)
--> 840             rval = self.fn(pyll_rval)
    841 
    842         if isinstance(rval, (float, int, np.number)):

/Users/nreeves/projects/automl/env/lib/python2.7/site-packages/hpsklearn/estimator.pyc in fn_with_timeout(*args, **kwargs)
    577             assert fn_rval[0] in ('raise', 'return')
    578             if fn_rval[0] == 'raise':
--> 579                 raise fn_rval[1]
    580 
    581             # -- remove potentially large objects from the rval

ValueError: Iteration of zero-sized operands is not enabled
bjkomer commented 7 years ago

It looks like the error is caused by an incompatibility with the newest version of numpy. I'm not sure if that is a numpy bug or if that change is intended. It works fine with version 1.11.0 but not 1.12.0.

As a workaround you could try switching to the previous numpy version. Something like pip install -I numpy==1.11.0 should do the trick.

Depending on which version of hyperopt-sklearn you are running, you might come across an error in the 5th cell saying there is no attribute _best_classif. That has been renamed to _best_learner when regressors were added. You can switch that line to instead print estimator._best_learner or even better, estimator.best_model() which should always work going forward. The notebook should really be updated to reflect that.

naoko commented 7 years ago

It sure did worked. Thank you very much! Maybe it is good idea to pin Numpy version. Also running Demo notebook required to install 2 libs that's not on setup.py

%%bash
pip install git+https://github.com/jaberg/skdata.git
pip install matplotlib

So I added that above import. I've made PR but feel free to reject. My feeling won't hurt :) especially notebook change (diff) is so ugly so I can understand! https://github.com/hyperopt/hyperopt-sklearn/pull/62

Thank you again for your quick response!