Skip to contents

Create a confusion matrix

Usage

conf_mat(data, truth, estimate, ...)

Arguments

data

A data frame containing the columns specified in truth and estimate.

truth

The column name containing the true values.

estimate

The column name containing the predicted values.

...

Additional arguments passed to yardstick::conf_mat.

Value

A confusion matrix.

Examples

if (FALSE) { # \dontrun{
library(dplyr)
data(mtcars)
# Create a binary outcome
mtcars <- mtcars %>% 
  mutate(vs_factor = factor(vs))
# Fit a model
model <- glm(vs ~ mpg + cyl, data = mtcars, family = "binomial")
# Make predictions
preds <- predict(model, type = "response")
# Create prediction data frame
pred_data <- mtcars %>%
  mutate(pred = factor(ifelse(preds > 0.5, 1, 0)))
# Calculate confusion matrix
conf_mat(pred_data, truth = vs_factor, estimate = pred)
} # }