View source: R/adjust-probability-threshold.R
adjust_probability_threshold | R Documentation |
Many machine learning systems determine hard class predictions by first predicting the probability of an event and then predicting that an event will occur if its respective probability is above 0.5. This adjustment allows practitioners to determine hard class predictions using a threshold other than 0.5. By setting appropriate thresholds, one can balance the trade-off between different types of errors (such as false positives and false negatives) to optimize the model's performance for specific use cases.
adjust_probability_threshold(x, threshold = 0.5)
x |
A |
threshold |
A numeric value (between zero and one) or |
An updated tailor()
containing the new operation.
This adjustment doesn't require estimation and, as such, the same data that's
used to train it with fit()
can be predicted on with predict()
; fitting
this adjustment just collects metadata on the supplied column names and does
not risk data leakage.
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.