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

AttributeError with numpy while using HyperoptEstimator #829

Closed
HarshSharma12 opened this issue Nov 19, 2021 · 10 comments · Fixed by hyperopt/hyperopt-sklearn#177
Closed
Labels

Comments

@HarshSharma12
Copy link

HarshSharma12 commented Nov 19, 2021

I tried using the HyperoptEstimator from hpsklearn and it gives me the following error

estim.fit(X_train, y_train)
  File "/home/harsh/anaconda3/envs/myenv/lib/python3.7/site-packages/hpsklearn/estimator.py", line 798, in fit
    fit_iter.send(increment)
  File "/home/harsh/anaconda3/envs/myenv/lib/python3.7/site-packages/hpsklearn/estimator.py", line 708, in fit_iter
    return_argmin=False, # -- in case no success so far
  File "/home/harsh/anaconda3/envs/myenv/lib/python3.7/site-packages/hyperopt/fmin.py", line 555, in fmin
    trials_save_file=trials_save_file,
  File "/home/harsh/anaconda3/envs/myenv/lib/python3.7/site-packages/hyperopt/base.py", line 688, in fmin
    trials_save_file=trials_save_file,
  File "/home/harsh/anaconda3/envs/myenv/lib/python3.7/site-packages/hyperopt/fmin.py", line 586, in fmin
    rval.exhaust()
  File "/home/harsh/anaconda3/envs/myenv/lib/python3.7/site-packages/hyperopt/fmin.py", line 364, in exhaust
    self.run(self.max_evals - n_done, block_until_done=self.asynchronous)
  File "/home/harsh/anaconda3/envs/myenv/lib/python3.7/site-packages/hyperopt/fmin.py", line 279, in run
    new_ids, self.domain, trials, self.rstate.integers(2 ** 31 - 1)
AttributeError: 'numpy.random.mtrand.RandomState' object has no attribute 'integers'

According to the numpy documentation on RandomState, there is no attribute integers. There is however a randint which seems to satisfy the requirements.

Library versions:

  • hpsklearn @ git+https://github.com/hyperopt/hyperopt-sklearn@c66f8df76003b5e72cb242399eeb139f951a1883
  • hyperopt==0.2.7
  • numpy==1.21.4

OS: Ubuntu 20.04

To replicate the error you can try the Complete example using the Iris dataset: from the documentation

@HarshSharma12 HarshSharma12 changed the title AttributeError while using HyperoptEstimator AttributeError with numpy while using HyperoptEstimator Nov 19, 2021
@mandjevant
Copy link
Contributor

@rharish101

@rharish101
Copy link
Contributor

rharish101 commented Nov 19, 2021

There was a change in hyperopt 0.2.7 0.2.6 that broke backwards compatibility with the deprecated np.random.RandomState to use the recommended np.random.Generator (and I wrote the commit 😬). I guess according to semantic versioning, hyperopt should've released v0.3.0 instead of v0.2.7 v0.2.6.

@HarshSharma12 you can downgrade hyperopt to v0.2.6 v0.2.5 to fix this issue for now. Long term, I guess hpsklearn should switch to using np.random.Generator. I can try to create a PR there, but I'm not 100% sure. EDIT: Just did it at hyperopt-sklearn#177.

@maxpumperla
Copy link
Contributor

exactly, sorry about that! 0.2.6 should have that change, too. so you'd need an earlier version than that.

@alexandschaefer
Copy link

Hi. I just had the same problem.
Wouldn't pinning or giving a range of the numpy version in setup.py prevent this? In a sense that contributors would not accidentally use an old numpy version.

@rharish101
Copy link
Contributor

@alexandschaefer You're right, I should've done that earlier 😓 . I've opened a new PR (#831) for this.

@B0Gec
Copy link

B0Gec commented Jan 6, 2022

There was a change in hyperopt 0.2.7 0.2.6 that broke backwards compatibility with the deprecated np.random.RandomState to use the recommended np.random.Generator (and I wrote the commit grimacing). I guess according to semantic versioning, hyperopt should've released v0.3.0 instead of v0.2.7 v0.2.6.

@HarshSharma12 you can downgrade hyperopt to v0.2.6 v0.2.5 to fix this issue for now. Long term, I guess hpsklearn should switch to using np.random.Generator. I can try to create a PR there, but I'm not 100% sure. EDIT: Just did it at hyperopt-sklearn#177.

Thanks, downgrading hyperopt to v0.2.5 solved this issue for me.

@rottentomato13
Copy link

There was a change in hyperopt 0.2.7 0.2.6 that broke backwards compatibility with the deprecated np.random.RandomState to use the recommended np.random.Generator (and I wrote the commit 😬). I guess according to semantic versioning, hyperopt should've released v0.3.0 instead of v0.2.7 v0.2.6.

@HarshSharma12 you can downgrade hyperopt to v0.2.6 v0.2.5 to fix this issue for now. Long term, I guess hpsklearn should switch to using np.random.Generator. I can try to create a PR there, but I'm not 100% sure. EDIT: Just did it at hyperopt-sklearn#177.

I downgraded hyperopt to v0.2.5 but it came up with another issue. it said hyperopt.pyll has no attribute 'base'

@usmandroid
Copy link

Had this issue in fmin.py file

~/miniforge3/envs/<venv-name>/lib/python3.9/site-packages/hyperopt/fmin.py

updated line 278-230: replacing integers with randint

new_trials = algo( new_ids, self.domain, trials, self.rstate.randint(2 ** 31 - 1) )

Previously

new_trials = algo( new_ids, self.domain, trials, self.rstate.integers(2 ** 31 - 1) )

solved the issue

@zhangms1709
Copy link

I'm also having an issue, I tried downgrading to version 0.2.5 but I'm still getting the same error with the fit function.

Copy link

github-actions bot commented Nov 5, 2023

This issue has been marked as stale because it has been open 120 days with no activity. Remove the stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Nov 5, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants