首页 > 解决方案 > RandomizedSearchCV 和 early_stopping_rounds

问题描述

我正在尝试n_estimators通过提前停止和 RandomizedSearchCV / GridSearchCV 获得最佳迭代。如果我打开verbose = True,我可以看到包括最佳迭代的输出:

提前停止,最佳迭代是:[852] valid_0's rmse: 0.108495

但是,我无法弄清楚如何通过命令访问它。

这是我的一段代码:

%%time

LGBM_model = lgb.LGBMRegressor(n_estimators = 10000)

LGBM_param_Random = {'reg_lambda': [0.01, 0.05],
                      'reg_alpha': [0.01, 0.05],
                      'min_child_samples': randint(1, 50),
                      'subsample': [x / 10 for x in range(1, 10, 1)],  
                      'subsample_freq': randint(1, 100),  
                      'num_leaves': randint(1, 100),
                      'max_depth': list(range(1, 15, 1)),
                      'max_bin': randint(1, 700),
                      'learning_rate': [x / 200 for x in range(1, 10, 1)],
                      'colsample_bytree': [x / 10 for x in range(1, 11, 1)]} 
                        
                    
LGBM_random_grid = RandomizedSearchCV(LGBM_model, LGBM_param_Random, 
                                      cv = CV, verbose = True, 
                                      n_jobs = 7, 
                                      scoring = 'neg_root_mean_squared_error', 
                                      n_iter = 50)

LGBM_fit = LGBM_random_grid.fit(x_train, y_train, 
                                early_stopping_rounds = 200, 
                                eval_set = [[x_test, y_test]], 
                                eval_metric = 'rmse', verbose = True)

round(-1*LGBM_fit.best_score_, 5)
LGBM_fit.best_params_

我试过LGBM_fit.best_iteration了,但它抛出了一个错误。

你能帮帮我吗?提前致谢!

标签: pythonmachine-learningscikit-learn

解决方案


推荐阅读