View source: R/make_class_pred.R
make_class_pred | R Documentation |
class_pred
vector from class probabilitiesThese functions can be used to convert class probability estimates to
class_pred
objects with an optional equivocal zone.
make_class_pred(..., levels, ordered = FALSE, min_prob = 1/length(levels))
make_two_class_pred(
estimate,
levels,
threshold = 0.5,
ordered = FALSE,
buffer = NULL
)
... |
Numeric vectors corresponding to class probabilities. There should
be one for each level in |
levels |
A character vector of class levels. The length should be the
same as the number of selections made through |
ordered |
A single logical to determine if the levels should be regarded
as ordered (in the order given). This results in a |
min_prob |
A single numeric value. If any probabilities are less than this value (by row), the row is marked as equivocal. |
estimate |
A single numeric vector corresponding to the class
probabilities of the first level in |
threshold |
A single numeric value for the threshold to call a row to
be labeled as the first value of |
buffer |
A numeric vector of length 1 or 2 for the buffer around
|
A vector of class class_pred
.
library(dplyr)
good <- segment_logistic$.pred_good
lvls <- levels(segment_logistic$Class)
# Equivocal zone of .5 +/- .15
make_two_class_pred(good, lvls, buffer = 0.15)
# Equivocal zone of c(.5 - .05, .5 + .15)
make_two_class_pred(good, lvls, buffer = c(0.05, 0.15))
# These functions are useful alongside dplyr::mutate()
segment_logistic %>%
mutate(
.class_pred = make_two_class_pred(
estimate = .pred_good,
levels = levels(Class),
buffer = 0.15
)
)
# Multi-class example
# Note that we provide class probability columns in the same
# order as the levels
species_probs %>%
mutate(
.class_pred = make_class_pred(
.pred_bobcat, .pred_coyote, .pred_gray_fox,
levels = levels(Species),
min_prob = .5
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.