小编san*_*tus的帖子

在 scikit-learn 中使用 skopt.BayesSearchCV 时如何修复“numpy.int”属性错误?

当我在官方文档上运行以下代码时,出现错误。

最小的例子

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)
Run Code Online (Sandbox Code Playgroud)

最后一行产生错误:

AttributeError …

python machine-learning scikit-learn scikit-optimize bayessearchcv

8
推荐指数
2
解决办法
5553
查看次数