
Plots and Tables from an XGBoost Machine Learning Model
Source:R/sus_mod_plot_ml.R
sus_mod_plot_ml.RdProduces feature importance charts, observed-vs-predicted scatter plots,
and cross-validation loss curves from a climasus_ml object returned by
sus_mod_ml().
Arguments
- x
A
climasus_mlobject produced bysus_mod_ml().- type
Character. Plot type:
"importance"(default),"fit", or"cv_log".- output_type
Character.
"plot"(default),"table", or"all"(named list$plot,$table,$data).- n_top
Integer. Maximum number of features to show in the importance plot. Default
20L.- interactive
Logical.
TRUEconverts the ggplot2 output to an interactive plotly widget. DefaultFALSE.- base_size
Numeric. ggplot2 base font size. Default
12.- save_plot
Character or
NULL. File path to save the plot.- lang
Character. Language for labels:
"pt"(default),"en","es".- verbose
Logical. Print progress messages. Default
FALSE.
Value
Depending on output_type:
"plot"-> aggplotorplotlyobject."table"-> atibbleof the plotted data."all"-> a named list:$plot,$table,$data.
Plot types (type)
type | Description |
"importance" | Horizontal bar chart of XGBoost feature Gain (top n_top features) |
"fit" | Observed vs. out-of-fold CV-predicted scatter with R² and RMSE annotation |
"cv_log" | Train/test loss per boosting round from xgb.cv(), with best-round marker |
Examples
if (FALSE) { # \dontrun{
ml <- sus_mod_ml(df, outcome_col = "n_obitos", feature_cols = c("tmax", "pop"))
sus_mod_plot_ml(ml, type = "importance", lang = "pt")
sus_mod_plot_ml(ml, type = "fit", lang = "en")
sus_mod_plot_ml(ml, type = "cv_log", lang = "es")
out <- sus_mod_plot_ml(ml, output_type = "all")
out$table
} # }