fit.tailor: Fit and predict from tailors

View source: R/tailor.R

fit.tailorR Documentation

Fit and predict from tailors

Description

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)

# 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()


tailor documentation built on Aug. 25, 2025, 9:50 a.m.