tailor | R Documentation |
Tailors compose iterative adjustments to model predictions. After
initializing a tailor with this function, add adjustment specifications
with adjust_*()
functions:
For probability distributions: adjust_probability_calibration()
For transformation of probabilities to hard class predictions:
adjust_probability_threshold()
, adjust_equivocal_zone()
For numeric distributions: adjust_numeric_calibration()
,
adjust_numeric_range()
For ad-hoc adjustments, see adjust_predictions_custom()
.
Tailors must be trained with fit() before being applied to new data with predict().
tailor()
An object of class tailor
with elements:
type
: The type of task (e.g., regression)
adjustments
: A list containing the sequential options specified by the
user.
columns
: the data set column names for the true outcome values and the
predictions of various types. If these are not specified, then NULL
.
These are usual
ptype
: a zero-row slice of the data containing the columns
.
Most of these values are set when an adjustment is added to the tailor or
when fit.tailor()
is used.
When composing multiple adjustments in a tailor object, the order matters and must follow specific rules depending on the type of predictions being adjusted (classification or regression).
For classification problems (binary and multiclass), adjustments that modify
probability estimates (e.g., adjust_probability_calibration()
) must be
applied before adjustments that change hard class predictions (including
adjust_equivocal_zone()
). This ensures that class predictions are based
on the final calibrated probabilities.
For regression problems, adjust_numeric_calibration()
must be applied
before other numeric adjustments. This ensures that subsequent adjustments
work with calibrated predictions.
Generally, adjustments cannot be duplicated (i.e. the same adjustment type
cannot be used multiple times in a tailor object), though
adjust_predictions_custom()
can be used multiple times. Adjustments for
different prediction types cannot be mixed—numeric adjustments (for
regression) and probability adjustments (for classification) cannot be
used in the same tailor object.
If these ordering rules are violated, tailor()
will raise an
error describing the issue.
library(dplyr)
library(modeldata)
# `predicted` gives hard class predictions based on probabilities
two_class_example |> count(predicted)
# change the probability threshold to allot one class vs the other
tlr <-
tailor() |>
adjust_probability_threshold(threshold = .1)
tlr
# fit by supplying column names.
tlr_fit <- fit(
tlr,
two_class_example,
outcome = c(truth),
estimate = c(predicted),
probabilities = c(Class1, Class2)
)
tlr_fit
# adjust hard class predictions
predict(tlr_fit, two_class_example) |> count(predicted)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.