簡體   English   中英

管道中的Hyperparametrs XGBOOST的正確名稱是什么?

[英]What is the correct name for Hyperparametrs XGBOOST in a Pipeline?

我正在處理分類問題,並且正在使用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()`.

管道中步驟的名稱不是xgb ,而是xgb的類名稱(即xgbclassifier )。 因此,您可以在parameters使用該名稱,也可以直接使用Pipeline而不是make_pipeline並根據需要設置步驟名稱,例如xgb

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM