Learn R Programming

tailor (version 0.1.0)

fit.tailor: 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 tailor
fit(object, .data, outcome, estimate, probabilities = c(), ...)

# S3 method for tailor predict(object, new_data, ...)

Value

An updated tailor() objects. Any estimates produced and saved by fit.tailor() are saved in the adjustments element of the tailor.

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.

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

Run this code
if (FALSE) { # rlang::is_installed(c("probably", "modeldata"))
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()
}

Run the code above in your browser using DataLab