|
1 | 1 | #' Declare post-processing for model predictions
|
2 | 2 | #'
|
| 3 | +#' @description |
| 4 | +#' |
| 5 | +#' Tailors compose iterative adjustments to model predictions. After |
| 6 | +#' initializing a tailor with this function, add adjustment specifications |
| 7 | +#' with `adjust_*()` functions: |
| 8 | +#' |
| 9 | +#' * For probability distributions: [adjust_probability_calibration()] |
| 10 | +#' * For transformation of probabilities to hard class predictions: |
| 11 | +#' [adjust_probability_threshold()], [adjust_equivocal_zone()] |
| 12 | +#' * For numeric distributions: [adjust_numeric_calibration], [adjust_numeric_range()] |
| 13 | +#' |
| 14 | +#' For ad-hoc adjustments, see [adjust_predictions_custom()]. |
| 15 | +#' |
| 16 | +#' Tailors must be trained with [fit()][fit.tailor()] before being applied to |
| 17 | +#' new data with [predict()][predict.tailor()]. Tailors are tightly integrated |
| 18 | +#' with the [tidymodels](https://tidymodels.org) framework; for greatest ease |
| 19 | +#' of use, situate tailors in model workflows with [workflows::add_tailor()]. |
| 20 | +#' |
3 | 21 | #' @param type The model sub-type. Possible values are `"unknown"`, `"regression"`,
|
4 | 22 | #' `"binary"`, or `"multiclass"`.
|
5 | 23 | #' @param outcome The name of the outcome variable.
|
|
9 | 27 | #' @param probabilities The names of class probability estimates (if any). For
|
10 | 28 | #' classification, these should be given in the order of the factor levels of
|
11 | 29 | #' the `estimate`.
|
12 |
| -#' @examples |
| 30 | +#' @examplesIf rlang::is_installed("modeldata") |
| 31 | +#' library(dplyr) |
| 32 | +#' library(modeldata) |
| 33 | +#' |
| 34 | +#' # `predicted` gives hard class predictions based on probabilities |
| 35 | +#' two_class_example %>% count(predicted) |
| 36 | +#' |
| 37 | +#' # change the probability threshold to allot one class vs the other |
| 38 | +#' tlr <- |
| 39 | +#' tailor() %>% |
| 40 | +#' adjust_probability_threshold(threshold = .1) |
| 41 | +#' |
| 42 | +#' tlr |
| 43 | +#' |
| 44 | +#' # fit by supplying column names. situate in a modeling workflow |
| 45 | +#' # with `workflows::add_tailor()` to avoid having to do so manually |
| 46 | +#' tlr_fit <- fit( |
| 47 | +#' tlr, |
| 48 | +#' two_class_example, |
| 49 | +#' outcome = c(truth), |
| 50 | +#' estimate = c(predicted), |
| 51 | +#' probabilities = c(Class1, Class2) |
| 52 | +#' ) |
| 53 | +#' |
| 54 | +#' tlr_fit |
13 | 55 | #'
|
14 |
| -#' tailor() |
| 56 | +#' # adjust hard class predictions |
| 57 | +#' predict(tlr_fit, two_class_example) %>% count(predicted) |
15 | 58 | #' @export
|
16 | 59 | tailor <- function(type = "unknown", outcome = NULL, estimate = NULL,
|
17 | 60 | probabilities = NULL) {
|
|
0 commit comments