When I run the following code on the official documentation, it has an error.
from skopt import BayesSearchCV
from sklearn.datasets import load_digits
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
X, y = load_digits(n_class=10, return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.75, test_size=.25, random_state=0)
# log-uniform: understand as search over p = exp(x) by varying x
opt = BayesSearchCV(
SVC(),
{
'C': (1e-6, 1e+6, 'log-uniform'),
'gamma': (1e-6, 1e+1, 'log-uniform'),
'degree': (1, 8), # integer valued parameter
'kernel': ['linear', 'poly', 'rbf'], # categorical parameter
},
n_iter=32,
cv=3
)
opt.fit(X_train, y_train)
The last line produces an error:
AttributeError module 'numpy' has no attribute 'int'.
np.intwas a deprecated alias for the builtinint. To avoid this error in existing code, useintby itself. Doing this will not modify any behavior and is safe. When replacingnp.int, you may wish to use e.g.np.int64ornp.int32to 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
How can I solve this problem? Are there other ways to implement Bayesian search?
Perhaps the version of skopt is too old. Are there other ways to implement Bayesian search? Besides grid search, random search, and bayes search, is there any other way to help me choose the hyperparameters of the machine learning model?
It's not clear which line of code is raising the exception but I suspect the culprit is skopt not having caught up with the full deprecation of
np.intin numpy. You could downgrade numpy to<1.24or this change could do: fromto
to pass the integer dimension as a array of integer.
Edit: I found this ongoing MR to fix the issue