Skip to contents

These functions apply fit() and predict() methods for each adjustment added to a tailor, in the order in which they were applied.

Usage

# S3 method for class 'tailor'
fit(object, .data, outcome, estimate, probabilities = c(), ...)

# S3 method for class 'tailor'
predict(object, new_data, ...)

Arguments

object

A tailor().

.data, new_data

A data frame containing predictions from a model.

outcome

<tidy-select> The column name of the outcome variable.

estimate

<tidy-select>

probabilities

<tidy-select> The column names of class probability estimates. These should be given in the order of the factor levels of the estimate.

...

Currently ignored.

Value

An updated tailor() objects. Any estimates produced and saved by fit.tailor() are saved in the adjustments element of the tailor.

Data Usage

For adjustments that don't require estimating parameters, training with fit() simply evaluates tidyselect expressions and logs column names. For others, as in adjust_numeric_calibration(), adjustments actually learn from data; in that case, separate subsets of data ought to be used for training the tailor and evaluating its performance on predictions.

Note that if .data has zero or one row, the method is changed to "none".

Examples

library(modeldata)

# `predicted` gives hard class predictions based on probability threshold .5
head(two_class_example)
#>    truth      Class1       Class2 predicted
#> 1 Class2 0.003589243 0.9964107574    Class2
#> 2 Class1 0.678621054 0.3213789460    Class1
#> 3 Class2 0.110893522 0.8891064779    Class2
#> 4 Class1 0.735161703 0.2648382969    Class1
#> 5 Class2 0.016239960 0.9837600397    Class2
#> 6 Class1 0.999275071 0.0007249286    Class1

# use a threshold of .1 instead:
tlr <-
  tailor() |>
  adjust_probability_threshold(.1)

# fit by supplying column names.
tlr_fit <- fit(
  tlr,
  two_class_example,
  outcome = c(truth),
  estimate = c(predicted),
  probabilities = c(Class1, Class2)
)

# adjust hard class predictions
predict(tlr_fit, two_class_example) |> head()
#> # A tibble: 6 × 4
#>   truth   Class1   Class2 predicted
#>   <fct>    <dbl>    <dbl> <fct>    
#> 1 Class2 0.00359 0.996    Class2   
#> 2 Class1 0.679   0.321    Class1   
#> 3 Class2 0.111   0.889    Class1   
#> 4 Class1 0.735   0.265    Class1   
#> 5 Class2 0.0162  0.984    Class2   
#> 6 Class1 0.999   0.000725 Class1