# Threshold Sweep Analysis

> Use when when you have predicted probabilities and binary true labels from a classifier and need to evaluate its discriminative ability across multiple operating points, or when you need to generate a publication-quality ROC curve with AUC to compare classifiers or communicate model performance to.

- Skill: `holobiomicslab/threshold-sweep-analysis` (Agent Skill)
- Install (CLI): `npx skillmds@latest add holobiomicslab/threshold-sweep-analysis`
- Raw SKILL.md: https://api.skillmd.com/api/skills/holobiomicslab/threshold-sweep-analysis/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- License: CC-BY-4.0
- Author: HolobiomicsLab (https://skillmd.com/u/holobiomicslab)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/holobiomicslab/threshold-sweep-analysis

---


# Threshold-sweep analysis

## Summary

A method to compute performance metrics (true positive rate, false positive rate, and AUC) across a range of classification thresholds to characterize classifier behavior and generate ROC curves. This skill is essential for evaluating binary classification models when threshold selection affects sensitivity–specificity trade-offs.

## When to use

When you have predicted probabilities and binary true labels from a classifier and need to evaluate its discriminative ability across multiple operating points, or when you need to generate a publication-quality ROC curve with AUC to compare classifiers or communicate model performance to stakeholders.

## When NOT to use

- Input is already a pre-computed ROC curve or threshold-independent metric (e.g., Cohen's kappa, F1 score at a fixed threshold).
- Binary classification is not the task (e.g., multiclass or regression problems without one-vs-rest reformulation).
- True labels are missing, imbalanced to a degree that invalidates ROC interpretation, or contain noise that was not accounted for in classifier training.

## Inputs

- CSV file with predicted probabilities and true binary labels (e.g., roc_example.csv)

## Outputs

- ROC curve visualization (PNG or PDF file)
- AUC metric value
- True positive rate and false positive rate arrays across thresholds

## How to apply

Load a CSV file containing predicted probabilities and true binary labels (e.g., roc_example.csv). Sweep across classification thresholds (typically 0 to 1 in increments of 0.01 or finer) and compute true positive rate (TPR) and false positive rate (FPR) at each threshold by comparing thresholded predictions against ground truth labels. Calculate the Area Under the Curve (AUC) metric by integrating the TPR-FPR curve using trapezoidal approximation or equivalent method. Render the ROC curve as a publication-quality figure with AUC displayed on the plot and save as PNG or PDF. Use R or Python statistical libraries (e.g., R's pROC package within Shiny) to automate these computations.

## Related tools

- **R Shiny** (Interactive web framework for implementing ROC curve visualization and threshold-sweep UI; handles CSV upload, threshold parameter sweeps, and plot rendering.) — github.com/databio2022/GraphBio

## Evaluation signals

- ROC curve monotonically increases from (0,0) to (1,1) in TPR vs. FPR space.
- AUC value lies in the range [0, 1], with 0.5 indicating random guessing and 1.0 perfect classification.
- Threshold sweep covers the full range [0, 1] with sufficient granularity (e.g., ≥100 points) to avoid visual stepping artifacts.
- Plot includes axis labels ('False Positive Rate', 'True Positive Rate'), legend with AUC value, and matches publication standards (e.g., vector format, readable fonts).
- Validation: recompute TPR and FPR at a subset of thresholds independently and confirm numerical agreement within machine precision.

## Limitations

- ROC curves are insensitive to class imbalance; precision-recall curves may be more informative for highly imbalanced datasets.
- AUC assumes a single scalar score per sample; ties in predicted probabilities can affect threshold-sweep accuracy if not handled carefully.
- Threshold selection for deployment must consider the specific cost matrix or business constraints; ROC analysis alone does not prescribe an optimal threshold.

## Evidence

- [other] Load the ROC demo CSV (roc_example.csv) containing predicted probabilities and true labels.: "Load the ROC demo CSV (roc_example.csv) containing predicted probabilities and true labels."
- [other] Calculate the ROC curve by computing true positive rate and false positive rate across classification thresholds using R or Python statistical libraries.: "Calculate the ROC curve by computing true positive rate and false positive rate across classification thresholds using R or Python statistical libraries."
- [other] Compute the Area Under the Curve (AUC) metric from the ROC curve.: "Compute the Area Under the Curve (AUC) metric from the ROC curve."
- [other] Render the ROC curve as a publication-quality figure with AUC displayed on the plot and save as a PNG or PDF file.: "Render the ROC curve as a publication-quality figure with AUC displayed on the plot and save as a PNG or PDF file."
- [readme] roc_example.csv for ROC curve: "roc_example.csv for ROC curve"

