R/utils.R

expand_preds <- function (.data, threshold, inc = NULL) {
  threshold <- unique(threshold)
  nth <- length(threshold)
  n_data <- nrow(.data)
  if (!is.null(inc))
    .data <- dplyr::select(.data, all_of(inc))
  .data <- .data[rep(1:nrow(.data), times = nth), ]
  .data$.threshold <- rep(threshold, each = n_data)
  .data
}

recode_data <- function (obs, prob, threshold) {  
  lvl <- levels(obs)
  binary_pred <- ifelse(prob >= threshold, lvl[1], lvl[2])
  factor(binary_pred, levels = lvl)
}

two_class = function (...) {
  mets <- yardstick::metric_set(yardstick::sens,
                                yardstick::spec)
  mets(...)
}
ML4LHS/runway documentation built on Sept. 9, 2023, 8:27 p.m.