TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Tumo505/SSL-for-ECG-classification/llms.txt
Use this file to discover all available pages before exploring further.
ssrl_ecg.visualization module provides a small set of functions that produce consistent, publication-quality matplotlib figures for all key SSRL-ECG experiments. Every function calls set_publication_style() to enforce 300 DPI resolution, uniform font sizes, and tight bounding boxes — so figures are ready to drop into a paper or report without further editing.
Setting the Publication Style
Before generating any figure, callset_publication_style() once. It configures global rcParams for the current Python session, affecting every subsequent plt call.
What it configures
Both screen display and saved files are rendered at 300 DPI, meeting the minimum requirement for most journal submissions.
Default figure size in inches. Individual plot functions may override this for specific layouts (e.g. the robustness bar chart uses
(9, 6)).Sans-serif font family at 11 pt base size, with axes labels at 12 pt and titles at 13 pt for clear readability at journal column widths.
Subtle background grid (30% opacity) aids quantitative reading without cluttering the figure.
Saves figures with a tight bounding box to avoid whitespace around the axes, which is the expected format for most submission systems.
plot_roc_curve()
Plots a ROC curve for a binary or multi-label classifier, annotates the legend with the AUC value, and draws the random-classifier diagonal.
Parameters
Ground-truth labels. Accepts 1-D binary arrays or 2-D multi-label matrices of shape
(N, C). For multi-label input, the mean across classes is used as the aggregate score.Predicted probabilities matching the shape of
y_true. For multi-label input, the per-sample mean probability is used.Legend label for this ROC curve. The computed AUC is appended automatically, e.g.
"SimCLR (AUC = 0.872)".Axes object to draw on. If
None, a new figure and axes are created automatically.Line colour for the ROC curve. Accepts any matplotlib colour string or hex code.
Return values
The figure object. Returns
None if an existing ax was passed in (figure ownership remains with the caller).The axes object with the ROC curve drawn on it. Useful for overlaying multiple curves.
The computed AUC value for this curve, calculated with
sklearn.metrics.auc.Overlaying multiple models
To compare several checkpoints on the same axes, pass the sameax object to each call:
Generating All Figures at Once
Thegenerate_visualizations.py script at the project root loads a fine-tuned checkpoint, runs inference on the PTB-XL test set, and writes all three publication figures to the figures/ directory.
Ensure prerequisites
The script requires a fine-tuned checkpoint at
checkpoints/ssl_finetuned_10pct.pt and the PTB-XL dataset at data/PTB-XL. Make sure the figures/ directory exists (it is created automatically).Output Figures
figures/roc_curve.png
ROC curves for each of the five cardiovascular classes plus the macro average. Shows per-class AUC and the random-classifier baseline diagonal.
figures/label_efficiency.png
AUROC vs label fraction (log scale x-axis) for SSL fine-tuned and supervised baseline, with shaded ±1 std bands. Illustrates the SSL advantage at low label fractions.
figures/robustness_comparison.png
Grouped bar chart comparing AUROC under clean, noisy (
noise_std=0.1), and masked (mask_ratio=0.2) conditions for each model variant.Evaluation Scripts in evaluation/
The evaluation/ directory contains four standalone scripts for deeper analysis. Each script is self-contained and can be run independently after checkpoints are available.
compare_baselines.py
Evaluates SimCLR, BYOL, ResNet-1D, and supervised checkpoints side-by-side on the PTB-XL test set. Prints a ranked summary table sorted by AUROC and identifies the best-performing method.
per_class_analysis.py
Computes per-class AUROC for BCE baseline vs focal-loss + oversampling. Highlights improvements for underrepresented classes such as HYP and CD, which were the original focus of the class-balancing work.
compare_losses.py
Runs a comprehensive comparison of BCE vs focal-loss training strategies on the test set, printing absolute and percentage AUROC/F1 differences and flagging whether improvements are positive on both metrics.
generate_publication_report.py
Combines multi-seed phase-2 results (from
results/phase2_multiseed_results.json) with phase-3 baseline comparisons to produce a formatted markdown table and statistical significance report (t-test, Cohen’s d).