abhishekkrthakur / approachingalmost

Approaching (Almost) Any Machine Learning Problem
7.34k stars 1.05k forks source link

Error with `gp_minimize` in Hyper-parameter Optimization Chapter #14

Open cleysonl opened 4 years ago

cleysonl commented 4 years ago

Hi, I am running the code for gp_minimize.py and in the following part of the code I get an error:

result = gp_minimize(
        optimization_function,
        dimensions=param_space,
        n_calls=15,
        n_random_starts=10,
        verbose=10)

The error is the following: Exception has occurred: TypeError '<' not supported between instances of 'Version' and 'tuple'

Going through the gp_minimize info there is an example:

res = gp_minimize(f,                  # the function to minimize
                  [(-2.0, 2.0)],      # the bounds on each dimension of x
                  acq_func="EI",      # the acquisition function
                  n_calls=15,         # the number of evaluations of f
                  n_random_starts=5,  # the number of random initialization points
                  noise=0.1**2,       # the noise level (optional)
                  random_state=1234)   # the random seed

Where [(-2.0, 2.0)] is what we have as param_space in the book but if I print the latter we get: [Integer(low=3, high=15, prior='uniform', transform='identity'), Integer(low=100, high=1500, prior='uniform', transform='identity'), Categorical(categories=('gini', 'entropy'), prior=None), Real(low=0.01, high=1, prior='uniform', transform='identity')] Wondering if the error is the way we are passing the values but didn't found anything.

abhishekkrthakur commented 4 years ago

Are you using the versions mentioned in this git repo?

cleysonl commented 4 years ago

Good point, I am using windows so maybe that's the problem. Let me go through it again using Linux and the exact same versions in the git repo and I'll come back to you.

abhishekkrthakur commented 4 years ago

If im not wrong, windows shouldn't be a problem. could you try creating environment from files mentioned in this repo? README file, in the end.?

cleysonl commented 4 years ago

Used the requirements.txt in the repo for my conda environment and still got the error.

(ml) C:\Users\leyso\Documents\Courses\Approaching almost all ML problems\Chapter 8\src>python rf_gp_minimize.py
[Integer(low=3, high=15, prior='uniform', transform='identity'), Integer(low=100, high=1500, prior='uniform', transform='identity'), Categorical(categories=('gini', 'entropy'), prior=None), Real(low=0.01, high=1, prior='uniform', transform='identity')]
Iteration No: 1 started. Evaluating function at random point.
Traceback (most recent call last):
  File "rf_gp_minimize.py", line 109, in <module>
    result = gp_minimize(
  File "C:\Users\leyso\anaconda3\envs\ml\lib\site-packages\skopt\optimizer\gp.py", line 264, in gp_minimize
    return base_minimize(
  File "C:\Users\leyso\anaconda3\envs\ml\lib\site-packages\skopt\optimizer\base.py", line 271, in base_minimize
    next_x = optimizer.ask()
  File "C:\Users\leyso\anaconda3\envs\ml\lib\site-packages\skopt\optimizer\optimizer.py", line 332, in ask
    return self._ask()
  File "C:\Users\leyso\anaconda3\envs\ml\lib\site-packages\skopt\optimizer\optimizer.py", line 398, in _ask
    return self.space.rvs(random_state=self.rng)[0]
  File "C:\Users\leyso\anaconda3\envs\ml\lib\site-packages\skopt\space\space.py", line 764, in rvs
    if sp_version < (0, 16):
TypeError: '<' not supported between instances of 'Version' and 'tuple'
cleysonl commented 4 years ago

Had to install scikit-optimize because it wasn't in the file requirements.txt. Which version are you using? I have 0.7.4

cleysonl commented 4 years ago

Just ran the exactly same code with a new environment created inside WSL2 using the requirements.txt file in the repo an runs perfectly. Maybe it is a Windows thing.