civic_thresholds: Threshold sweep for binary classification

View source: R/civic_data_utils.R

civic_thresholdsR Documentation

Threshold sweep for binary classification

Description

Computes performance metrics across a grid of decision thresholds. Essential for understanding the accuracy-vs-fairness tradeoffs that arise when choosing a classification cutoff — a DataCitizen-Pro democratic judgment teaching tool.

Usage

civic_thresholds(
  y_true,
  y_prob,
  positive = NULL,
  thresholds = seq(0.1, 0.9, by = 0.05)
)

Arguments

y_true

Factor of true class labels.

y_prob

Numeric vector of predicted probabilities for the positive class.

positive

Character. Positive class level.

thresholds

Numeric vector of thresholds to evaluate. Default: 'seq(0.1, 0.9, by = 0.05)'.

Value

A tibble with one row per threshold and columns: 'threshold', 'accuracy', 'balanced_acc', 'precision', 'recall', 'specificity', 'f1', 'rate_positive'.

Examples

y <- factor(sample(c("yes","no"), 200, replace = TRUE))
p <- runif(200)
thr <- civic_thresholds(y, p, positive = "yes")
civic_plot_thresholds(thr)

civic.icarm documentation built on June 18, 2026, 1:06 a.m.