probably (version 0.0.2)

append_class_pred: Add a class_pred column

Description

This function is similar to make_class_pred(), but is useful when you have a large number of class probability columns and want to use tidyselect helpers. It appends the new class_pred vector as a column on the original data frame.

Usage

append_class_pred(.data, ..., levels, ordered = FALSE,
  min_prob = 1/length(levels), name = ".class_pred")

Arguments

.data

A data frame or tibble.

...

One or more unquoted expressions separated by commas to capture the columns of .data containing the class probabilities. You can treat variable names like they are positions, so you can use expressions like x:y to select ranges of variables or use selector functions to choose which columns. For make_class_pred, the columns for all class probabilities should be selected (in the same order as the levels object). For two_class_pred, a vector of class probabilities should be selected.

levels

A character vector of class levels. The length should be the same as the number of selections made through ..., or length 2 for make_two_class_pred().

ordered

A single logical to determine if the levels should be regarded as ordered (in the order given). This results in a class_pred object that is flagged as ordered.

min_prob

A single numeric value. If any probabilities are less than this value (by row), the row is marked as equivocal.

name

A single character value for the name of the appended class_pred column.

Value

.data with an extra class_pred column appended onto it.

Examples

Run this code
# NOT RUN {
# The following two examples are equivalent and demonstrate
# the helper, append_class_pred()

library(dplyr)

species_probs %>%
  mutate(
    .class_pred = make_class_pred(
      .pred_bobcat, .pred_coyote, .pred_gray_fox,
      levels = levels(Species),
      min_prob = .5
    )
  )

lvls <- levels(species_probs$Species)

append_class_pred(
  .data = species_probs,
  contains(".pred_"),
  levels = lvls,
  min_prob = .5
)

# }

Run the code above in your browser using DataCamp Workspace