This repository has been archived by the owner on Feb 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 549
using BayesSearchCV AttributeError module 'numpy' has no attribute 'int'. np.int was a deprecated alias for the builtin int. To avoid this error in existing code, use int by itself. Doing this will not modify any behavior and is safe. When replacing np.int, you may wish to use e.g. np.int64 or np.int32 to specify the precision. If you wish to review your current use, check the release note link for additional information. #1200
Comments
Got same problem with the following code: opt = BayesSearchCV(
SVR(),
{
'C': (1e-6, 1e+6, 'log-uniform'),
'gamma': (1e-6, 1e+1, 'log-uniform'),
'degree': (1, 8),
'kernel': ['linear', 'poly', 'rbf'],
},
n_iter=10,
cv=5
)
opt.fit(trainX, trainY) # RAISE AN ERROR AT THIS LINE
print("validation Score: ", opt.best_score_)
print("test score: ", opt.score(testX, testY))
I guess downgrade numpy to < 1.20 will fix this problem? |
that is because of BayesSearchCV.fit() function uses the np.int, you can go to skopt's library position and edit the 'the site-packages\skopt\space\transformers.py' by replacing all np.int with int it will fix |
A workaround that worked for me is to put these lines before fitting the estimator:
|
Another example that fails the same way. Are there any plans to fix this bug? It's pretty old. import numpy as np
import matplotlib.pyplot as plt
from warnings import filterwarnings
from skopt.plots import plot_convergence
from skopt import gp_minimize
filterwarnings('ignore') # suppress some of the warnings from B.O.
np.random.seed(42)
# same "bumpy" function as in simulated annealing, just written differently
# assumes xy is a list or array-like with xy = [x, y]
def bumpy(xy):
x = xy[0]
y = xy[1]
obj = (
0.2
+ x**2
+ y**2
- 0.1 * np.cos(6 * np.pi * x)
- 0.1 * np.cos(6 * np.pi * y)
)
return obj
# call the optimization.
res = gp_minimize(
bumpy, # the function to minimize
[(-1, 1), (-1, 1)], # the bounds on each dimension of x
acq_func="EI", # the acquisition function
n_calls=20, # the number of evaluations of the objective function
n_random_starts=5, # the number of random initialization points
random_state=42,
) # the random seed
print(
f'The minimum value of f(x) is {res.fun:0.4f} and occurs at x={res.x[0]:0.4f}, y={res.x[1]:0.4f}'
)
print(
f'Recall that the objective function may include noise, so the optimized function value may not be exact.'
)
fig = plt.figure(
figsize=(10, 6)
) # we initialize the plot so we can control dimensions
ax = fig.add_axes
plot_convergence(res, ax) |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
when run bayes_cv.fit() get error
AttributeError module 'numpy' has no attribute 'int'. np.int was a deprecated alias for the builtin int. To avoid this error in existing code, use int by itself. Doing this will not modify any behavior and is safe. When replacing np.int, you may wish to use e.g. np.int64 or np.int32 to specify the precision. If you wish to review your current use, check the release note link for additional information.
it is due to the line opt.fit() that raises the error. More precisely, BayesSearchCV.fit() uses np.int. replaced all np.int with int in the file 'site-packages\skopt\space\transformers.py'
reference
https://stackoverflow.com/questions/76321820/how-to-fix-the-numpy-int-attribute-error-when-using-skopt-bayessearchcv-in-sci
The text was updated successfully, but these errors were encountered: