0

我正在对 XGB 分类器的以下参数执行 GridSearch。这很简单,但是当我运行grid_search.fit(X_train, y_train)它时它会返回ValueError: Invalid parameter xgb for estimator

我完成了一个xgb.get_params()确认使用了正确的参数并且它们都检查了 - 见xgb.get_params()下文。我什至甚至将参数/值复制/粘贴到代码中以查看它们是否可以工作,但我仍然收到相同的错误

代码:

preprocessing = Pipeline(steps=[('ct', ColumnTransformer(transformers=[
                                ('cat', cat_transformer, cat_features),
                                ('num', num_transformer, num_features)],
                                remainder = 'passthrough')),
                                ('svd', TruncatedSVD(n_components=8)),
                                ('feature_selection', selector)])
params = {"xgb__eta": [0.1], 
          "xgb__gamma": [0],
          "xgb__max_depth":[3],
          "xgb__min_child_weight": [1],
          "xgb__lambda": [1],
}

pipe = Pipeline(steps=[('preprocessing', preprocessing), ('classifier', XGBClassifier())])

grid_search = GridSearchCV(pipe, params, cv=10, scoring='roc_auc')

grid_search.fit(X_train, y_train)

xgb.get_params()

{'base_score': 0.5,
 'booster': 'gbtree',
 'colsample_bylevel': 1,
 'colsample_bynode': 1,
 'colsample_bytree': 1,
 'gamma': 0,
 'learning_rate': 0.1,
 'max_delta_step': 0,
 'max_depth': 3,
 'min_child_weight': 1,
 'missing': None,
 'n_estimators': 100,
 'n_jobs': 1,
 'nthread': None,
 'objective': 'binary:logistic',
 'random_state': 0,
 'reg_alpha': 0,
 'reg_lambda': 1,
 'scale_pos_weight': 1,
 'seed': None,
 'silent': None,
 'subsample': 1,
 'verbosity': 1}
```````

4

1 回答 1

0

您指的是您的分类器,因为xgb该变量未在任何地方声明。

指定参数的正确方法是使用classifier__前缀,因为这是您在管道中引用 XGBoostClassifier 的方式。因此,您应该将params密钥更改为:

params = {"classifier__eta": [0.1], 
          "classifier__gamma": [0],
          "classifier__max_depth":[3],
          "classifier__min_child_weight": [1],
          "classifier__lambda": [1],
}

或者,相反,更改classifierxgb

pipe = Pipeline(steps=[('preprocessing', preprocessing), ('xgb', XGBClassifier())])
于 2022-01-07T22:41:52.793 回答