我正在处理分类问题,并且正在使用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()`.
答案 0 :(得分:1)
管道中步骤的名称不是xgb
,而是小写的类名称(即xgbclassifier
)。因此,您可以在parameters
中使用该名称,也可以直接使用Pipeline
而不是make_pipeline
并根据需要设置步骤名称,例如xgb