Skip to contents

This function plots the confusion matrix from a tuned xgboost model.

Usage

plotConfMat(last_fit, name, metric_df, output_dir)

Arguments

last_fit

The last fit from the tuning process.

name

A character string of the name of the model.

metric_df

A data frame containing the metric

output_dir

The directory to save the plot.

Value

A ggplot2 object.

Examples

set.seed(12)
mtcars$cluster <- as.character(mtcars$am)
folds <- rsample::vfold_cv(mtcars, v = 2)
rec <- recipes::recipe(cluster ~ ., data = mtcars)
mod <- parsnip::logistic_reg()
control <- tune::control_resamples(save_pred = TRUE)
metrics <- yardstick::metric_set(
    yardstick::accuracy,
    yardstick::bal_accuracy,
    yardstick::f_meas,
    yardstick::roc_auc
)
res <- tune::fit_resamples(mod, rec, folds, control = control, metrics = metrics)
metric_df <- tune::collect_metrics(res)
metric_df$.estimate <- metric_df$mean
plotConfMat(res, name = "model", output_dir = tempdir(), metric_df = metric_df)
#> Scale for fill is already present.
#> Adding another scale for fill, which will replace the existing scale.