【发布时间】:2018-04-17 07:44:51
【问题描述】:
我目前正在尝试使用RandomizedSearchCV 或GridSearchCV 优化超参数。为了比较,我想尝试 hyperopt,它也可以作为 hyperopt-sklearn (https://github.com/hyperopt/hyperopt-sklearn) 使用。可惜文档不多,不知道怎么用。
有没有像我现在使用随机和网格搜索一样使用 hyperopt 的类似方法?
skf = StratifiedKFold(n_splits=5, random_state=42)
params_randomSearch = {"min_samples_leaf": np.arange(1,30,1),
"min_samples_split": np.arange(2,20,1),
"max_depth": np.arange(2, 20, 1),
"min_weight_fraction_leaf": np.arange(0. ,0.4, 0.1),
"max_features" : ['auto', 'sqrt', 'log2', None],
"criterion" : ['entropy', 'gini']}
scoring = {'Accuracy' : make_scorer(accuracy_score), 'Recall' : 'recall_weighted', 'Kappa' : make_scorer(cohen_kappa_score)}
rs = RandomizedSearchCV(DecisionTreeClassifier(random_state=42), param_distributions=params_randomSearch, scoring = scoring, cv = skf, refit = 'Accuracy', n_iter=150, n_jobs=-1, random_state=42)
rs.fit(x_train, y_train)
y_predict = rs.best_estimator_.predict(x_test)
acc = accuracy_score(y_test, y_predict)
根据 github 上的文档/示例,应该是这样的:
estim = HyperoptEstimator(classifier=random_forest('RF1'))
estim.fit(x_train, y_train)
这会导致以下错误:
TypeError: 'generator' object is not subscriptable
我的另一个问题是,是否有任何集成的交叉验证选项,例如 RandomizedSearchCV 或 GridSearchCV?
【问题讨论】:
标签: python machine-learning hyperparameters