Skip to contents

Draw calibration plot

Usage

draw_calibration(
  true_labels,
  predicted_prob,
  n_bins = 10L,
  bin_method = c("quantile", "equidistant"),
  binclasspos = 2L,
  main = NULL,
  subtitle = NULL,
  xlab = "Mean predicted probability",
  ylab = "Empirical risk",
  show_marginal_x = TRUE,
  marginal_x_y = -0.02,
  marginal_col = NULL,
  marginal_size = 10,
  mode = "markers+lines",
  show_brier = TRUE,
  theme = rtemis_theme,
  filename = NULL,
  ...
)

Arguments

true_labels

Factor or list of factors with true class labels

predicted_prob

Numeric vector or list of numeric vectors with predicted probabilities

n_bins

Integer: Number of windows to split the data into

bin_method

Character: "quantile" or "equidistant": Method to bin the estimated probabilities.

binclasspos

Integer: Index of the positive class

main

Character: Main title

subtitle

Character: Subtitle, placed bottom right of plot

xlab

Character: x-axis label

ylab

Character: y-axis label

show_marginal_x

Logical: Add marginal plot of distribution of estimated probabilities

marginal_x_y

Numeric: y position of marginal plot

marginal_col

Character: Color of marginal plot

marginal_size

Numeric: Size of marginal plot

mode

Character: "lines", "markers", "lines+markers": How to plot.

show_brier

Logical: If TRUE, add Brier scores to trace names.

theme

Character or list: Theme to use for plot

filename

Character: Path to save output.

...

Additional arguments passed to draw_scatter

Value

A plotly object.

Author

EDG

Examples

if (FALSE) { # \dontrun{
data(segment_logistic, package = "probably")

# Plot the calibration curve of the original predictions
draw_calibration(
  true_labels = segment_logistic$Class,
  predicted_prob = segment_logistic$.pred_poor,
  n_bins = 10L,
  binclasspos = 2L
)

# Plot the calibration curve of the calibrated predictions
draw_calibration(
  true_labels = segment_logistic$Class,
  predicted_prob = calibrate(
    segment_logistic$Class,
    segment_logistic$.pred_poor
  )$fitted.values,
  n_bins = 10L,
  binclasspos = 2L
)
} # }