【问题标题】:What is the correct name for Hyperparametrs XGBOOST in a Pipeline?管道中超参数 XGBOOST 的正确名称是什么?
【发布时间】:2019-09-14 01:06:33
【问题描述】:

我正在研究一个分类问题,我正在使用 Grisearch 方法来寻找最佳超参数。但是,我正在使用管道架构来构建相同的分类模型,只更改分类器。 xgboost 的错误是参数的字符串。你有什么建议吗?


        elif method == "XGBoost":

            #classifier = Boosting
            classifier = XGBClassifier(random_state = 0, n_jobs = 4)

            parameters = {"xgb__max_depth":[3,4,5,6,7,9],
                          "xgb__gamma":[0, 0.1, 0.2],
                          "xgb__colsample_bytree":[0.5,0.6,0.7,0.8,0.9],                
                          "xgb__n_estimators": [10, 50, 100, 500],
                          "xgb__learning_rate": [0.1, 0.5, 1],
                          'xgb__min_child_weight': [1, 3, 4, 5, 6]

                    }


        print("Start PIPELINE !!!")

        # Add one transformers and two samplers in the pipeline object
        pipeline = make_pipeline(renn, smote_enn, classifier)
        #pipeline = make_pipeline(knn)
        print()
        print(" Starting Grid Search, with this method: " + method)
        print()


    #If it is not clear review the link from Stack
    #https://stackoverflow.com/questions/48370150/how-to-implement-smote-in-cross-validation-and-gridsearchcv

        scorers = {
                'precision_score': make_scorer(precision_score, pos_label="1"),
                'recall_score': make_scorer(recall_score, pos_label="1"),
                'accuracy_score': make_scorer(accuracy_score),
                'f1_scorer': make_scorer(f1_score, pos_label="1")
            }

        random_search = GridSearchCV(pipeline,  param_grid = parameters ,
                                           cv = kf,  scoring = scorers, refit = 'recall_score')
        gg = random_search.fit(X, y)

但是我得到了这个错误:

ValueError: Invalid parameter xgb for estimator Pipeline(memory=None,
steps=[('repeatededitednearestneighbours', RepeatedEditedNearestNeighbours(kind_sel='all', max_iter=100, n_jobs=2,
n_neighbors=5, random_state=0, ratio=None,
return_indices=False, sampling_strategy='auto')), ('smoteenn', SMOTEENN(enn=None, random_state=0, ratio=None, ...
reg_alpha=0, reg_lambda=1, scale_pos_weight=1, seed=None,
silent=True, subsample=1))]). Check the list of available parameters with `estimator.get_params().keys()`.

【问题讨论】:

    标签: python python-3.x pipeline xgboost


    【解决方案1】:

    管道中步骤的名称不是xgb,而是小写的类名(即xgbclassifier)。因此,要么在 parameters 中使用该名称,要么直接使用 Pipeline 而不是 make_pipeline 并根据需要设置步骤名称,例如xgb

    【讨论】:

      猜你喜欢
      • 2021-09-13
      • 1970-01-01
      • 2018-06-05
      • 1970-01-01
      • 1970-01-01
      • 2010-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多