如何使用 MultiOutputRegressor 包装器为 XGBoost 的网格搜索参数

How to grid search parameter for XGBoost with MultiOutputRegressor wrapper

我正在尝试构建一个回归器,以使用 XGBoostMultiOutputRegressor 包装器从 6D 输入预测到 6D 输出。但我不确定如何进行参数搜索。我的代码如下所示:

gsc = GridSearchCV(
            estimator=xgb.XGBRegressor(),
            param_grid={"learning_rate": (0.05, 0.10, 0.15),
                        "max_depth": [ 3, 4, 5, 6, 8],
                        "min_child_weight": [ 1, 3, 5, 7],
                        "gamma":[ 0.0, 0.1, 0.2],
                        "colsample_bytree":[ 0.3, 0.4],},
            cv=3, scoring='neg_mean_squared_error', verbose=0, n_jobs=-1)

grid_result = MultiOutputRegressor(gsc).fit(X_train, y_train)
self.best_params = grid_result.best_params_

但是,MultiOutputRegressor 没有 .best_params_ 变量。这样做的正确方法是什么?非常感谢!!!

MultiOutputRegressor 有估计器本身,param_grid 需要相应地改变。


from xgboost import XGBRegressor
from sklearn.model_selection import GridSearchCV
from sklearn.datasets import make_regression
from sklearn.multioutput import MultiOutputRegressor

X_train, y_train = make_regression(n_features=6, n_targets=6)

gsc = GridSearchCV(
            estimator=MultiOutputRegressor(XGBRegressor()),
            param_grid={"estimator__learning_rate": (0.05, 0.10, 0.15)},
            cv=3, scoring='neg_mean_squared_error', verbose=0, n_jobs=-1)

grid_result = gsc.fit(X_train, y_train)
print(grid_result.best_params_)

# {'estimator__learning_rate': 0.1}

你可以试试这个

gsc = GridSearchCV(
            estimator=xgb.XGBRegressor(),
            param_grid={"learning_rate": (0.05, 0.10, 0.15),
                        "max_depth": [ 3, 4, 5, 6, 8],
                        "min_child_weight": [ 1, 3, 5, 7],
                        "gamma":[ 0.0, 0.1, 0.2],
                        "colsample_bytree":[ 0.3, 0.4],},
            cv=3, scoring='neg_mean_squared_error', verbose=0, n_jobs=-1)

grid_result = MultiOutputRegressor(gsc).fit(X_train, y_train)

self.best_params = grid_result.estimators_[0].best_params_  # for the first y_target estimator