如何传递fit_params以适应RandomizedSearchCV使索引超出范围错误

时间:2017-05-29 19:24:54

标签: python scikit-learn xgboost

我正在尝试使用XGBRegressor估计器拟合RandomizedSearchCV,并希望将params传递给fit方法。特别是我想设置XGBRegressor的停止循环和评估指标。以下代码为我提供了索引超出范围错误

xgb_fit_params = {'eval_metric': 'rmse', 
              'early_stopping_rounds': 50,
              'eval_set' :None
             }
xgb_param_grid = {'reg_alpha': [0.1, 0.5, 1, 2, 3],
              'reg_lambda': [0.1, 0.5, 1, 2, 3, 4],
              'gamma':[0, 0.1, 0,5, 1],
              'colsample_bytree': [0.6,0.7, 0.8],
              'max_depth' : [4,5,6]
             }

model = xgb.XGBRegressor(max_depth=5, 
                    learning_rate=0.035, 
                    n_estimators=1000, 
                    silent=False, 
                    objective='reg:linear', 
                    min_child_weight=1, 
                    max_delta_step=0, 
                    subsample=1, 
                    scale_pos_weight=1, 
                    seed=2866) 

random_search = RandomizedSearchCV(model, 
                               param_distributions=xgb_param_grid,
                               n_iter=20,
                               verbose=2,
                               n_jobs=-1,
                               fit_params=xgb_fit_params,
                               random_state=2866)
random_search.fit(X_train_all, y_train)

0 个答案:

没有答案