Comments (4)
A workaround that worked for me is to put these lines before fitting the estimator:
import numpy as np
np.int = int
from scikit-optimize.
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))AttributeError Traceback (most recent call last) [~\AppData\Local\Temp/ipykernel_7760/3848764104.py](https://file+.vscode-resource.vscode-cdn.net/e%3A/Programming/pythonAI/sklearn/~/AppData/Local/Temp/ipykernel_7760/3848764104.py) in <module> 14 ) 15 ---> 16 opt.fit(trainX, trainY) 17 18 print("validation Score: ", opt.best_score_) [d:\Python\lib\site-packages\skopt\searchcv.py](file:///D:/Python/lib/site-packages/skopt/searchcv.py) in fit(self, X, y, groups, callback, **fit_params) 464 self.optimizer_kwargs_ = dict(self.optimizer_kwargs) 465 --> 466 super().fit(X=X, y=y, groups=groups, **fit_params) 467 468 # BaseSearchCV never ranked train scores, [d:\Python\lib\site-packages\sklearn\base.py](file:///D:/Python/lib/site-packages/sklearn/base.py) in wrapper(estimator, *args, **kwargs) 1150 ) 1151 ): -> 1152 return fit_method(estimator, *args, **kwargs) 1153 1154 return wrapper [d:\Python\lib\site-packages\sklearn\model_selection\_search.py](file:///D:/Python/lib/site-packages/sklearn/model_selection/_search.py) in fit(self, X, y, groups, **fit_params) 896 return results ... 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. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
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
I pass the error by this method
from scikit-optimize.
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))
AttributeError Traceback (most recent call last)
[~\AppData\Local\Temp/ipykernel_7760/3848764104.py](https://file+.vscode-resource.vscode-cdn.net/e%3A/Programming/pythonAI/sklearn/~/AppData/Local/Temp/ipykernel_7760/3848764104.py) in <module>
14 )
15
---> 16 opt.fit(trainX, trainY)
17
18 print("validation Score: ", opt.best_score_)
[d:\Python\lib\site-packages\skopt\searchcv.py](file:///D:/Python/lib/site-packages/skopt/searchcv.py) in fit(self, X, y, groups, callback, **fit_params)
464 self.optimizer_kwargs_ = dict(self.optimizer_kwargs)
465
--> 466 super().fit(X=X, y=y, groups=groups, **fit_params)
467
468 # BaseSearchCV never ranked train scores,
[d:\Python\lib\site-packages\sklearn\base.py](file:///D:/Python/lib/site-packages/sklearn/base.py) in wrapper(estimator, *args, **kwargs)
1150 )
1151 ):
-> 1152 return fit_method(estimator, *args, **kwargs)
1153
1154 return wrapper
[d:\Python\lib\site-packages\sklearn\model_selection\_search.py](file:///D:/Python/lib/site-packages/sklearn/model_selection/_search.py) in fit(self, X, y, groups, **fit_params)
896 return results
...
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.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
I guess downgrade numpy to < 1.20 will fix this problem?
from scikit-optimize.
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)
from scikit-optimize.
Related Issues (20)
- mse needs updating (to friedman_mse?) HOT 1
- Question: Are plot_convergence and plot_objective supposed to look like identical plots?
- gp_minimize callback arguments / return value
- Bug Latin Hypercube sampling
- space.Integer and space.Float not allowed to be constant
- `np.int` was a deprecated alias for the builtin `int`. HOT 17
- First and last values of each variable in the space are sampled 2 times less than the others
- Repeated error Using Forest_optimize HOT 1
- Something about earlystopping HOT 1
- Optimization space and initial points in x0 use inconsistent dimensions.
- How to introduce customized stop criteria HOT 1
- Inclusion of PRIMA solvers in Skit-Optimize HOT 5
- LOO in BayesSearchCV
- Error in strategy-comparison.ipynb
- AttributeError: 'Sum' object has no attribute 'gradient_x' when using sci-kit learn RBF for sci-kit optimize gp_minimize HOT 3
- Question: How to initialize a model in 4D search space, but run trials in only 2D for the first 100 trials through ask-tell interface. Then expand to 4D.
- Reproducibility when using BayesSearchCV with MLPRegressor
- AttributeError when using deprecated alias np.int in NumPy HOT 1
- Scikit optimize abandoned? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scikit-optimize.