calibrate: Calibrate predicted probabilities using GAM

View source: R/calibrate.R

calibrateR Documentation

Calibrate predicted probabilities using GAM

Description

Calibrate predicted probabilities using a generalized additive model (GAM).

Usage

calibrate(
  true.labels,
  est.prob,
  pos.class.idi = 1,
  mod = c("gam", "glm"),
  k = 5,
  verbose = TRUE
)

Arguments

true.labels

Factor with true class labels

est.prob

Numeric vector with predicted probabilities

pos.class.idi

Integer: Index of the positive class

mod

Character: Model to use for calibration. Either "gam" or "glm"

k

Integer: GAM degrees of freedom

verbose

Logical: If TRUE, print messages to the console

Value

mod: fitted GAM model. Use mod$fitted.values to get calibrated input probabilities; use predict(mod, newdata = newdata, type = "response") to calibrate other estimated probabilities.

Author(s)

EDG

Examples

## Not run: 
data(segment_logistic, package = "probably")

# Plot the calibration curve of the original predictions
dplot3_calibration(
  true.labels = segment_logistic$Class,
  est.prob = segment_logistic$.pred_poor,
  n_windows = 10,
  pos.class.idi = 2
)

# Plot the calibration curve of the calibrated predictions
dplot3_calibration(
  true.labels = segment_logistic$Class,
  est.prob = calibrate(
    segment_logistic$Class,
    segment_logistic$.pred_poor
  )$fitted.values,
  n_windows = 10,
  pos.class.idi = 2
)

## End(Not run)

egenn/rtemis documentation built on April 24, 2024, 6:58 p.m.