pythonscikit-learnxgboost

How to grid search parameter for XGBoost with MultiOutputRegressor wrapper


I'm trying to build a regressor to predict from a 6D input to a 6D output using XGBoost with the MultiOutputRegressor wrapper. I'm not sure how to do the parameter search. My code looks like this:

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_

However, the MultiOutputRegressor does not have the .best_params_ variable. What's the right way to do this?


Solution

  • You can try this

    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