简体   繁体   中英

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

I'm working in a classification problem, and I'm using the Grisearch method for finding the optimal hyperparameters. However I'm using the architecture of a pipeline for build the same classification model changing only the classifier. The error for the xgboost is the string for the parameters. Do you have some advices ?


        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)

However I have obtained this error:

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()`.

The name of the step in the pipeline is not xgb but rather the class name in low case (ie xgbclassifier ). So either you use that name in parameters or use Pipeline directly instead of make_pipeline and set the step name as you wish, eg xgb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM