hyperopt / hyperopt-sklearn

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

Error when calling estim.fit() when all trials time out #67

Open bjkomer opened 7 years ago

bjkomer commented 7 years ago

Something like this:

...
estim = HyperoptEstimator( classifier=clf, trial_timeout=1)
estim.fit(X_train, y_train)

Results in this error: AttributeError: 'hyperopt_estimator' object has no attribute '_best_preprocs'

tchaton commented 6 years ago

I have the same error

danielrahmani commented 6 years ago

I have the same problem. Is there a way to fix this?

andyogah commented 6 years ago

I am having exactly the same issue. Is this issue fixed yet?

meenaparam commented 6 years ago

I also have this error, but not consistently. Sometimes quitting python and then re-running in a fresh session means the same code doesn't fail.

ZSCDumin commented 5 years ago

Something like this:

...
estim = HyperoptEstimator( classifier=clf, trial_timeout=1)
estim.fit(X_train, y_train)

Results in this error: AttributeError: 'hyperopt_estimator' object has no attribute '_best_preprocs'

Reinstall using: pip install networkx==1.11, can solve that problem

Eric-L-Manibardo commented 5 years ago

I`m working with this library for the past few days, and this problem comes when there is not any trial with STATUS_OK (produced by the short timeout), so when collecting the candidates, the list remains empty. I've edited the /.local/lib/python3.6/site-packages/hyperopt/base.py file approximately at line 500 like this:

`def best_trial(self):

    candidates = [t for t in self.trials
                  if t['result']['status'] == STATUS_OK]
    #losses = [float(t['result']['loss']) for t in candidates]    

    if not candidates: #en caso de que el primero no tenga STATUS_OK  
        losses = [1.0]
        print('Loss of this itteration is: {} (it does not converge...)'.format(losses))
        return self.trials[0]
    else:
        losses = [float(t['result']['loss']) for t in candidates]
        print('Last STATUS_OK loss: {}'.format(losses[-1]))
        best = np.argmin(losses)
        return candidates[best]`

This way the program does not crash while there is almost one valid trial.