Skip to contents

This adjustment functions allows for arbitrary transformations of model predictions using dplyr::mutate() statements.

Usage

adjust_predictions_custom(x, ..., .pkgs = character(0))

Arguments

x

A tailor().

...

Name-value pairs of expressions. See dplyr::mutate().

.pkgs

A character string of extra packages that are needed to execute the commands.

Data Usage

This adjustment doesn't require estimation and, as such, the same data that's used to train it with fit() can be predicted on with predict(); fitting this adjustment just collects metadata on the supplied column names and does not risk data leakage.

Examples

library(modeldata)

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

tlr <-
  tailor() %>%
  adjust_equivocal_zone() %>%
  adjust_predictions_custom(linear_predictor = binomial()$linkfun(Class2))

tlr_fit <- fit(
  tlr,
  two_class_example,
  outcome = c(truth),
  estimate = c(predicted),
  probabilities = c(Class1, Class2)
)

predict(tlr_fit, two_class_example) %>% head()
#> # A tibble: 6 × 5
#>   truth   Class1   Class2  predicted linear_predictor
#>   <fct>    <dbl>    <dbl> <clss_prd>            <dbl>
#> 1 Class2 0.00359 0.996        Class2            5.63 
#> 2 Class1 0.679   0.321        Class1           -0.747
#> 3 Class2 0.111   0.889        Class2            2.08 
#> 4 Class1 0.735   0.265        Class1           -1.02 
#> 5 Class2 0.0162  0.984        Class2            4.10 
#> 6 Class1 0.999   0.000725     Class1           -7.23