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:
- Returns:
Figure object.
- Return type:
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:
- Returns:
Figure object.
- Return type:
Example:
fig = plot_roc_compare( [result_lr, result_rf, result_xgb], labels=["Logistic", "Random Forest", "XGBoost"], )
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)"
)