roc Module#

ROC curve visualizations.

This module provides functions for plotting ROC curves, comparing multiple models, and precision-recall curves for imbalanced datasets.

Functions#

episia.viz.roc.plot_roc(result, *, title='ROC Curve', animate=False, backend='plotly', theme='scientific', config=None)[source]#

Plot a single ROC curve with AUC annotation and optimal threshold marker.

Parameters:
  • result (Any) – ROCResult from stats.diagnostic.roc_analysis().

  • title (str) – Figure title.

  • animate (bool) – Trace the curve from (0,0) to (1,1) (Plotly only).

  • backend (str) – ‘plotly’ (default) or ‘matplotlib’.

  • theme (str) – Theme name.

  • config (PlotConfig | None) – Full PlotConfig override.

Returns:

Figure object.

Return type:

Any

Example:

from episia.stats.diagnostic import roc_analysis
from episia.viz.roc import plot_roc

result = roc_analysis(y_true, y_score)
plot_roc(result, title="Malaria RDT  ROC").show()
episia.viz.roc.plot_roc_compare(results, labels=None, *, title='ROC Curve Comparison', backend='plotly', theme='scientific', config=None)[source]#

Overlay multiple ROC curves for model comparison.

Parameters:
  • results (List[Any]) – List of ROCResult objects.

  • labels (List[str] | None) – Display name for each curve (defaults to ‘Model 1’, ‘Model 2’…).

  • title (str) – Figure title.

  • backend (str) – ‘plotly’ or ‘matplotlib’.

  • theme (str) – Theme name.

  • config (PlotConfig | None) – Full PlotConfig override.

Returns:

Figure object.

Return type:

Any

Example:

fig = plot_roc_compare(
    [result_lr, result_rf, result_xgb],
    labels=["Logistic", "Random Forest", "XGBoost"],
)
episia.viz.roc.plot_precision_recall(y_true, y_score, *, label='Model', title='Precision-Recall Curve', backend='plotly', theme='scientific', config=None)[source]#

Plot a precision-recall curve.

More informative than ROC when classes are imbalanced.

Parameters:
  • y_true (Any) – True binary labels.

  • y_score (Any) – Predicted probabilities or scores.

  • label (str) – Curve label.

  • title (str) – Figure title.

  • backend (str) – ‘plotly’ or ‘matplotlib’.

  • theme (str) – Theme name.

  • config (PlotConfig | None) – Full PlotConfig override.

Returns:

Figure object.

Return type:

Any

Examples#

Single ROC curve:

from episia.stats.diagnostic import roc_analysis
from episia.viz.roc import plot_roc

# Perform ROC analysis
roc_result = roc_analysis(y_true, y_scores)

# Plot with AUC annotation
fig = plot_roc(roc_result, title="Diagnostic Test Performance")
fig.show()

Animated ROC curve:

# Animated threshold sweep
fig = plot_roc(
    roc_result,
    animate=True,
    title="ROC Curve - Threshold Sweep"
)

Comparing multiple models:

from episia.viz.roc import plot_roc_compare

models = [roc_logistic, roc_rf, roc_xgb]
labels = ["Logistic Regression", "Random Forest", "XGBoost"]

fig = plot_roc_compare(
    models,
    labels=labels,
    title="Model Comparison - ROC Curves"
)

Precision-recall curve:

from episia.viz.roc import plot_precision_recall

fig = plot_precision_recall(
    y_true,
    y_scores,
    label="Logistic Regression",
    title="Precision-Recall Curve (Imbalanced Data)"
)