Add tune_lgbm() and wire hyperparameter tuning into DAG

Converts scratch/tune_model.R into a pure tune_lgbm() function,
replacing hardcoded winning_params with a fully automated tar_target.
Best params (trees=844, depth=3, lr=0.0204, min_n=389) now flow
reproducibly into evaluate_final_model() and train_production_model().
PR-AUC improved from 0.165 to 0.198.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-22 03:25:35 -05:00
parent 33d0fc31c7
commit f47b2e1be2
7 changed files with 178 additions and 9 deletions

View File

@@ -23,6 +23,7 @@ export(save_report_figure)
export(save_report_table)
export(train_diag_model)
export(train_production_model)
export(tune_lgbm)
importFrom(arrow,S3FileSystem)
importFrom(arrow,open_dataset)
importFrom(arrow,read_csv_arrow)
@@ -43,6 +44,11 @@ importFrom(cowplot,theme_cowplot)
importFrom(cowplot,theme_half_open)
importFrom(cowplot,theme_minimal_grid)
importFrom(cowplot,theme_minimal_vgrid)
importFrom(dials,grid_space_filling)
importFrom(dials,learn_rate)
importFrom(dials,min_n)
importFrom(dials,tree_depth)
importFrom(dials,trees)
importFrom(dplyr,`%>%`)
importFrom(dplyr,across)
importFrom(dplyr,any_of)
@@ -105,6 +111,7 @@ importFrom(lubridate,"%m+%")
importFrom(parsnip,boost_tree)
importFrom(parsnip,set_engine)
importFrom(parsnip,set_mode)
importFrom(purrr,map)
importFrom(quarto,quarto_render)
importFrom(readr,write_rds)
importFrom(recipes,all_nominal_predictors)
@@ -120,6 +127,8 @@ importFrom(recipes,step_novel)
importFrom(recipes,step_unknown)
importFrom(recipes,step_zv)
importFrom(recipes,update_role)
importFrom(rsample,make_splits)
importFrom(rsample,manual_rset)
importFrom(scales,percent)
importFrom(stats,reorder)
importFrom(stats,sd)
@@ -131,9 +140,14 @@ importFrom(themis,smote)
importFrom(themis,step_tomek)
importFrom(tidyr,pivot_longer)
importFrom(tidyselect,where)
importFrom(tune,control_grid)
importFrom(tune,select_best)
importFrom(tune,tune)
importFrom(tune,tune_grid)
importFrom(workflows,add_model)
importFrom(workflows,add_recipe)
importFrom(workflows,extract_fit_engine)
importFrom(workflows,fit)
importFrom(workflows,workflow)
importFrom(yardstick,metric_set)
importFrom(yardstick,pr_auc)