R/probFunction.R

Defines functions probFunction

Documented in probFunction

#' @rdname caret-internal
#' @export
probFunction <- function(
  method,
  modelFit,
  newdata = NULL,
  preProc = NULL,
  param = NULL
) {
  if (!is.null(newdata) && !is.null(preProc)) {
    newdata <- predict(preProc, newdata)
  }

  obsLevels <- levels(modelFit)

  classProb <- method$prob(
    modelFit = modelFit,
    newdata = newdata,
    submodels = param
  )
  if (!is.data.frame(classProb) && is.null(param)) {
    classProb <- as.data.frame(classProb, stringsAsFactors = TRUE)
    if (!is.null(obsLevels)) {
      classProb <- classProb[, obsLevels, drop = FALSE]
    }
  }
  classProb
}

Try the caret package in your browser

Any scripts or data that you put into this service are public.

caret documentation built on Nov. 15, 2026, 9:06 a.m.