Skip to contents

Tailors compose iterative adjustments to model predictions. After initializing a tailor with this function, add adjustment specifications with adjust_*() functions:

For ad-hoc adjustments, see adjust_predictions_custom().

Tailors must be trained with fit() before being applied to new data with predict(). Tailors are tightly integrated with the tidymodels framework; for greatest ease of use, situate tailors in model workflows with ?workflows::add_tailor().

Usage

tailor(outcome = NULL, estimate = NULL, probabilities = NULL)

Arguments

outcome

<tidy-select> Only required when used independently of ?workflows::add_tailor(), and can also be passed at fit() time instead. The column name of the outcome variable.

estimate

<tidy-select> Only required when used independently of ?workflows::add_tailor(), and can also be passed at fit() time instead. The column name of the point estimate (e.g. predicted class), In tidymodels, this corresponds to column names .pred, .pred_class, or .pred_time.

probabilities

<tidy-select> Only required when used independently of ?workflows::add_tailor() for the "binary" or "multiclass" types, and can also be passed at fit() time instead. The column names of class probability estimates. These should be given in the order of the factor levels of the estimate.

Examples

library(dplyr)
library(modeldata)

# `predicted` gives hard class predictions based on probabilities
two_class_example %>% count(predicted)
#>   predicted   n
#> 1    Class1 277
#> 2    Class2 223

# change the probability threshold to allot one class vs the other
tlr <-
  tailor() %>%
  adjust_probability_threshold(threshold = .1)

tlr
#> 
#> ── tailor ──────────────────────────────────────────────────────────────────────
#> A binary postprocessor with 1 adjustment:
#> 
#>  Adjust probability threshold to 0.1.

# fit by supplying column names. situate in a modeling workflow
# with `workflows::add_tailor()` to avoid having to do so manually
tlr_fit <- fit(
  tlr,
  two_class_example,
  outcome = c(truth),
  estimate = c(predicted),
  probabilities = c(Class1, Class2)
)

tlr_fit
#> 
#> ── tailor ──────────────────────────────────────────────────────────────────────
#> A binary postprocessor with 1 adjustment:
#> 
#>  Adjust probability threshold to 0.1. [trained]

# adjust hard class predictions
predict(tlr_fit, two_class_example) %>% count(predicted)
#> # A tibble: 2 × 2
#>   predicted     n
#>   <fct>     <int>
#> 1 Class1      362
#> 2 Class2      138