【问题标题】:Hyperparameter tuning using hyperopt sklearn with RandomForestClassifier使用带有 RandomForestClassifier 的 hyperopt sklearn 进行超参数调整
【发布时间】:2018-04-17 07:44:51
【问题描述】:

我目前正在尝试使用RandomizedSearchCVGridSearchCV 优化超参数。为了比较,我想尝试 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

我的另一个问题是,是否有任何集成的交叉验证选项,例如 RandomizedSearchCVGridSearchCV

【问题讨论】:

    标签: python machine-learning hyperparameters


    【解决方案1】:

    我可以自己解决。好像和networkx v2有些冲突。降级到1.11 可以解决问题 (https://github.com/hyperopt/hyperopt/issues/333)

    【讨论】:

      猜你喜欢
      • 2020-09-10
      • 2014-06-11
      • 2022-11-10
      • 2019-02-23
      • 1970-01-01
      • 2021-08-11
      • 2021-01-20
      • 2018-12-07
      • 2019-11-13
      相关资源
      最近更新 更多