Skip to content

Commit 5b82fe7

Browse files
committed
document tailor() (closes #33)
1 parent 4cb5f86 commit 5b82fe7

File tree

3 files changed

+91
-5
lines changed

3 files changed

+91
-5
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Imports:
3030
tidyselect
3131
Suggests:
3232
modeldata,
33-
testthat (>= 3.0.0)
33+
testthat (>= 3.0.0),
34+
workflows
3435
Remotes:
3536
tidymodels/probably
3637
Config/testthat/edition: 3

R/tailor.R

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
#' Declare post-processing for model predictions
22
#'
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+
#'
321
#' @param type The model sub-type. Possible values are `"unknown"`, `"regression"`,
422
#' `"binary"`, or `"multiclass"`.
523
#' @param outcome The name of the outcome variable.
@@ -9,9 +27,34 @@
927
#' @param probabilities The names of class probability estimates (if any). For
1028
#' classification, these should be given in the order of the factor levels of
1129
#' 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
1355
#'
14-
#' tailor()
56+
#' # adjust hard class predictions
57+
#' predict(tlr_fit, two_class_example) %>% count(predicted)
1558
#' @export
1659
tailor <- function(type = "unknown", outcome = NULL, estimate = NULL,
1760
probabilities = NULL) {

man/tailor.Rd

Lines changed: 44 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)