python - 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
了,但它抛出了一个错误。
你能帮帮我吗?提前致谢!
解决方案
推荐阅读
- google-apps-script - 如何计算excel或工作表上一行中未突出显示的条目数
- android - 使用 android App 设置 Android TV 的输入
- python - 如何在 Selenium 和 Firefox 中检索原始 JSON 数据?
- css - CSS未在codeigniter 4中加载
- python - 有没有办法遍历列表和函数?
- postgresql - 如何使用 pgAdmin4 为数据库中的所有触发器和表生成脚本
- java - Google Drive API V3 下载返回 416 错误
- amazon-web-services - 负载均衡器初始请求容量
- javascript - 列表正在更新,但相应的本地存储未更新
- thrift - 异常结束时的 Thrift 消息