deepecgkit.analysis¶
Multi-seed analysis over finished training runs: discovery and aggregation of run directories,
ranking stability, the statistics behind both, and LaTeX table emitters. These modules back the
deepecg aggregate and deepecg rank commands.
Aggregation¶
Discovers run directories (any directory holding classification_metrics.csv), groups them by
model, dataset and seed, and summarises every metric across seeds.
aggregation
¶
Discovery and aggregation of finished training runs.
A run directory is usable when it holds classification_metrics.csv. Two
schemas are written by :mod:deepecgkit.evaluation.report depending on whether
the task is multi-label, and they share only precision, recall, f1, auroc and
the calibration columns, so the schema and the averaging mode travel with every
record.
Every metric name is looked up defensively, so runs produced before a metric
existed stay readable and simply contribute nothing to it. The
calibration_bins column is deliberately not a metric: averaging a bin count
across seeds would be meaningless.
RunRecord
¶
Bases: NamedTuple
One finished training run and the metrics it produced.
Source code in deepecgkit/analysis/aggregation.py
read_run_metrics
¶
Read one run directory into a record.
Model and dataset come from the metrics CSV, which is authoritative. The
seed comes from run_metadata.json when present and falls back to a
seed<N> suffix on the directory name, so runs produced before seeds
were recorded remain readable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_dir
|
Path
|
Directory holding classification_metrics.csv. |
required |
Returns:
| Type | Description |
|---|---|
RunRecord | None
|
A populated record, or None when the directory holds no usable metrics. |
Source code in deepecgkit/analysis/aggregation.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
discover_runs
¶
discover_runs(
roots: Sequence[Path],
recursive: bool = False,
include_legacy: bool = False,
on_duplicate: str = ON_DUPLICATE_NEWEST,
include_failed: bool = False,
) -> tuple[list[RunRecord], dict[str, list[str]]]
Collect usable runs beneath the given roots.
A run whose run_metadata.json records a non-zero returncode (the
batch runner writes the training subprocess's exit status there) failed
after writing its metrics and is set aside under the "failed" diagnostic
unless include_failed is given. Runs without a recorded status are
kept.
Two runs count as duplicates when they share dataset, model, seed and, when
recorded, the batch runner's params_fingerprint; runs of one pairing
and seed with different hyperparameters are therefore kept apart rather
than resolved by modification time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
roots
|
Sequence[Path]
|
Directories to search. |
required |
recursive
|
bool
|
Search at any depth rather than only immediate children. |
False
|
include_legacy
|
bool
|
Keep runs whose seed could not be determined, tagging them with a sentinel seed so they are visible but never silently pooled with seeded runs. |
False
|
on_duplicate
|
str
|
One of "newest", "error" or "all", controlling what happens when the same model, dataset and seed appear twice. |
ON_DUPLICATE_NEWEST
|
include_failed
|
bool
|
Keep runs whose recorded exit status is non-zero. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[list[RunRecord], dict[str, list[str]]]
|
The records and a diagnostics mapping from reason to directory names. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If on_duplicate is unrecognised, or is "error" and a duplicate is found. |
Source code in deepecgkit/analysis/aggregation.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
runs_to_frame
¶
Flatten records into one row per run and metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
Sequence[RunRecord]
|
Discovered runs. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A long frame with columns run_dir, model, dataset, seed, averaging, |
DataFrame
|
multi_label, n_train, n_val, n_test, n_test_groups, metric and value. |
Source code in deepecgkit/analysis/aggregation.py
reconcile_averaging
¶
Drop runs whose averaging mode disagrees with their group's majority.
resolve_average returns "binary" whenever the test split holds two or
fewer classes, so precision, recall and F1 are positive-class values there
and macro elsewhere. Pooling the two would average incommensurable
quantities. The minority is dropped rather than blanking the whole cell,
because one unlucky split should not discard four sound runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs
|
DataFrame
|
Long frame from :func: |
required |
Returns:
| Type | Description |
|---|---|
tuple[DataFrame, DataFrame]
|
The surviving rows and a frame describing what was dropped. |
Source code in deepecgkit/analysis/aggregation.py
aggregate_runs
¶
Summarise every metric across seeds for each dataset and model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs
|
DataFrame
|
Long frame from :func: |
required |
confidence_level
|
float
|
Two-sided coverage for the Student-t interval. |
CONFIDENCE_LEVEL
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per dataset, model and metric with mean, std, sem, interval |
DataFrame
|
bounds, the usable count and the contributing seeds. |
Source code in deepecgkit/analysis/aggregation.py
Ranking¶
Rank stability and cross-dataset flip tests across random seeds: per-seed ranks, rank distributions, Kendall's tau between seeds, and paired comparisons between models.
ranking
¶
Ranking stability and cross-dataset flip tests across random seeds.
Ranks are formed inside a single dataset and seed, so the averaging differences between datasets never contaminate them. Comparisons between two models on one dataset are paired: within a seed both models see the same split, so the split effect cancels in the difference.
rank_within_seed
¶
Rank models inside each dataset and seed, best first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs
|
DataFrame
|
Long frame of per-run metric values. |
required |
metric
|
str
|
Metric to rank on. |
DEFAULT_RANK_METRIC
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A frame with dataset, seed, model, value, rank and rank_average. Ties |
DataFrame
|
share the better rank under "min" for display, while rank_average is |
DataFrame
|
used for Kendall's tau. |
Source code in deepecgkit/analysis/ranking.py
rank_distribution
¶
Count how often each model attained each rank.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs
|
DataFrame
|
Long frame of per-run metric values. |
required |
metric
|
str
|
Metric to rank on. |
DEFAULT_RANK_METRIC
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per dataset and model with a rank_ |
DataFrame
|
attainable rank, the modal rank, the fraction of seeds at that rank, |
DataFrame
|
and the fraction of seeds spent at rank one. |
Source code in deepecgkit/analysis/ranking.py
tau_summary
¶
Kendall's tau-b between every pair of per-seed rankings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs
|
DataFrame
|
Long frame of per-run metric values. |
required |
metric
|
str
|
Metric to rank on. |
DEFAULT_RANK_METRIC
|
Returns:
| Name | Type | Description |
|---|---|---|
DataFrame
|
One row per dataset with the mean, minimum and maximum tau over all |
|
DataFrame
|
seed pairs, the number of pairs, and the smallest two-sided p-value |
|
DataFrame
|
the coefficient could attain given the number of models. No p-value is |
|
computed |
DataFrame
|
at four models that floor is 0.083, so significance is |
DataFrame
|
unreachable and the statistic is descriptive only. |
Source code in deepecgkit/analysis/ranking.py
paired_difference
¶
paired_difference(
runs: DataFrame,
model_a: str,
model_b: str,
dataset: str,
metric: str = DEFAULT_RANK_METRIC,
confidence_level: float = CONFIDENCE_LEVEL,
correction: str = NADEAU_BENGIO,
min_test_groups: int = MIN_TEST_GROUPS,
) -> dict[str, Any]
Paired per-seed difference between two models on one dataset.
Pairing is exact: within a seed both models train and evaluate on the same split, so the split effect cancels. Across seeds the splits overlap heavily, so the standard error carries the Nadeau-Bengio correction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs
|
DataFrame
|
Long frame of per-run metric values. |
required |
model_a
|
str
|
Model whose score is the minuend. |
required |
model_b
|
str
|
Model whose score is the subtrahend. |
required |
dataset
|
str
|
Dataset to compare on. |
required |
metric
|
str
|
Metric to compare. |
DEFAULT_RANK_METRIC
|
confidence_level
|
float
|
Two-sided coverage. |
CONFIDENCE_LEVEL
|
correction
|
str
|
Standard error correction, "nadeau-bengio" or "none". |
NADEAU_BENGIO
|
min_test_groups
|
int
|
Fewest independent test units that can support an interval. |
MIN_TEST_GROUPS
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The paired summary augmented with seeds, averaging, the recorded split |
dict[str, Any]
|
sizes, a bimodality flag and a reason string. |
Source code in deepecgkit/analysis/ranking.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
flip_test
¶
flip_test(
runs: DataFrame,
model_a: str,
model_b: str,
dataset_1: str,
dataset_2: str,
metric: str = DEFAULT_RANK_METRIC,
confidence_level: float = CONFIDENCE_LEVEL,
correction: str = NADEAU_BENGIO,
min_test_groups: int = MIN_TEST_GROUPS,
min_seeds: int = MIN_SEEDS_FOR_INTERVAL,
min_seeds_for_claim: int = MIN_SEEDS_FOR_CLAIM,
) -> dict[str, Any]
Intersection-union test for a cross-dataset ranking reversal.
The reversal is supported only when both paired intervals exclude zero with opposite signs. Because the decision requires both components, no multiplicity correction is applied between them, and the reported p is the larger of the two. That p is an upper bound: pairing two-sided intervals with a sign requirement is a one-sided test at half the nominal level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs
|
DataFrame
|
Long frame of per-run metric values. |
required |
model_a
|
str
|
First model. |
required |
model_b
|
str
|
Second model. |
required |
dataset_1
|
str
|
Dataset on which A is expected to lead. |
required |
dataset_2
|
str
|
Dataset on which B is expected to lead. |
required |
metric
|
str
|
Metric to compare. |
DEFAULT_RANK_METRIC
|
confidence_level
|
float
|
Two-sided coverage. |
CONFIDENCE_LEVEL
|
correction
|
str
|
Standard error correction. |
NADEAU_BENGIO
|
min_test_groups
|
int
|
Fewest independent test units that can support a test. |
MIN_TEST_GROUPS
|
min_seeds
|
int
|
Fewest seeds for which an interval is computed at all. |
MIN_SEEDS_FOR_INTERVAL
|
min_seeds_for_claim
|
int
|
Fewest seeds that may yield a supported verdict. |
MIN_SEEDS_FOR_CLAIM
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Both paired summaries, the verdict, p_flip, and the averaging modes |
dict[str, Any]
|
with a flag for whether the two magnitudes are comparable. |
Source code in deepecgkit/analysis/ranking.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |
all_flip_tests
¶
all_flip_tests(
runs: DataFrame,
metric: str = DEFAULT_RANK_METRIC,
confidence_level: float = CONFIDENCE_LEVEL,
correction: str = NADEAU_BENGIO,
models: Sequence[str] | None = None,
datasets: Sequence[str] | None = None,
min_test_groups: int = MIN_TEST_GROUPS,
fdr_family: str = FDR_FAMILY_TESTABLE,
) -> pd.DataFrame
Run a flip test for every model pair shared by every dataset pair.
Only models present on both datasets of a pair are compared, because
models that failed to converge were omitted from some datasets. The
exploratory grid is adjusted with Benjamini-Yekutieli over the family
chosen by fdr_family: every testable comparison (the default, so that
the family does not depend on the outcomes), or only the comparisons
whose verdict is supported, suggestive or contradicted (the historical
behaviour, whose family size depends on the verdicts).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs
|
DataFrame
|
Long frame of per-run metric values. |
required |
metric
|
str
|
Metric to compare. |
DEFAULT_RANK_METRIC
|
confidence_level
|
float
|
Two-sided coverage. |
CONFIDENCE_LEVEL
|
correction
|
str
|
Standard error correction. |
NADEAU_BENGIO
|
models
|
Sequence[str] | None
|
Restrict to these models. |
None
|
datasets
|
Sequence[str] | None
|
Restrict to these datasets. |
None
|
min_test_groups
|
int
|
Fewest independent test units that can support a test. |
MIN_TEST_GROUPS
|
fdr_family
|
str
|
FDR_FAMILY_TESTABLE or FDR_FAMILY_SIGNIFICANT. |
FDR_FAMILY_TESTABLE
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per tested combination, with raw and adjusted p-values and |
DataFrame
|
the family definition in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fdr_family is unknown. |
Source code in deepecgkit/analysis/ranking.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | |
evaluate_rank_claim
¶
evaluate_rank_claim(
runs: DataFrame,
model: str,
dataset_best: str,
dataset_worst: str,
metric: str = DEFAULT_RANK_METRIC,
opponents: Sequence[str] | None = None,
confidence_level: float = CONFIDENCE_LEVEL,
correction: str = NADEAU_BENGIO,
min_test_groups: int = MIN_TEST_GROUPS,
) -> dict[str, Any]
Decompose a "best here, worst there" claim into component flip tests.
Every model present on both datasets is a component. Components that cannot be tested are reported as untestable rather than dropped, so the claim is never presented as supported on a silently reduced subset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs
|
DataFrame
|
Long frame of per-run metric values. |
required |
model
|
str
|
The model the claim is about. |
required |
dataset_best
|
str
|
Dataset on which the model is claimed strongest. |
required |
dataset_worst
|
str
|
Dataset on which the model is claimed weakest. |
required |
metric
|
str
|
Metric to compare. |
DEFAULT_RANK_METRIC
|
opponents
|
Sequence[str] | None
|
Restrict the components to these models. |
None
|
confidence_level
|
float
|
Two-sided coverage. |
CONFIDENCE_LEVEL
|
correction
|
str
|
Standard error correction. |
NADEAU_BENGIO
|
min_test_groups
|
int
|
Fewest independent test units that can support a test. |
MIN_TEST_GROUPS
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The component results, the overall verdict and the governing p-value. |
Source code in deepecgkit/analysis/ranking.py
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 | |
Statistics¶
Summary statistics and paired tests over per-seed scalar metrics, including Student-t intervals and the Nadeau-Bengio correction.
statistics
¶
Statistics for summarising and comparing metrics across repeated training runs.
The functions here operate on plain sequences of per-seed scalars. They are
deliberately separate from :mod:deepecgkit.evaluation.evaluator, whose
bootstrap_evaluate resamples individual test samples and recomputes metrics
from predictions; that estimator cannot consume a handful of finished run
scores. The output key names mirror it so the two read alike.
summarize_scores
¶
summarize_scores(
values: Sequence[float],
confidence_level: float = CONFIDENCE_LEVEL,
) -> dict[str, float]
Summarise one metric across seeds with a two-sided Student-t interval.
Non-finite entries are dropped first, so "n" counts usable values rather than attempted runs. The t distribution is used because with three to ten seeds the variance is estimated from the same points; a percentile bootstrap over so few scalars cannot place an endpoint outside their observed range and therefore understates the interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Sequence[float]
|
Per-seed values of a single metric. |
required |
confidence_level
|
float
|
Two-sided coverage. |
CONFIDENCE_LEVEL
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Mapping with "mean", "std" (sample standard deviation, ddof=1), |
dict[str, float]
|
"sem", "lower_ci", "upper_ci" and "n". With a single value the |
dict[str, float]
|
dispersion and interval keys are NaN rather than zero. With no values |
dict[str, float]
|
every key but "n" is NaN. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If confidence_level is not strictly between 0 and 1. |
Source code in deepecgkit/analysis/statistics.py
nadeau_bengio_factor
¶
Variance inflation factor for repeated random subsampling.
When every seed redraws the train/test partition of one fixed corpus the
per-seed differences share training data and are positively correlated, so
the ordinary standard error understates the spread. Nadeau and Bengio
(2003), Machine Learning 52(3), replace 1 / n with
1 / n + n_test / n_train.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of usable seeds. |
required |
n_train
|
int | None
|
Training set size, or None when it was not recorded. |
required |
n_test
|
int | None
|
Test set size, or None when it was not recorded. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The multiplier applied to the sample standard deviation to obtain the |
float
|
corrected standard error. Falls back to the uncorrected |
float
|
|
Source code in deepecgkit/analysis/statistics.py
paired_summary
¶
paired_summary(
differences: Sequence[float],
confidence_level: float = CONFIDENCE_LEVEL,
correction: str = NADEAU_BENGIO,
n_train: int | None = None,
n_test: int | None = None,
) -> dict[str, float]
Summarise paired per-seed differences and test them against zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
differences
|
Sequence[float]
|
One difference per shared seed. |
required |
confidence_level
|
float
|
Two-sided coverage. |
CONFIDENCE_LEVEL
|
correction
|
str
|
Either "nadeau-bengio" or "none". |
NADEAU_BENGIO
|
n_train
|
int | None
|
Mean training set size across the contributing runs. |
None
|
n_test
|
int | None
|
Mean test set size across the contributing runs. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Mapping with "mean", "std", "sem", "lower_ci", "upper_ci", "t_stat", |
dict[str, float]
|
"p_value", "n", "n_wins" and "excludes_zero". A degenerate sample with |
dict[str, float]
|
zero variance yields NaN for the interval and the p-value rather than a |
dict[str, float]
|
zero-width interval, because zero observed spread is not infinite |
dict[str, float]
|
precision. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If correction is not a recognised name. |
Source code in deepecgkit/analysis/statistics.py
kendall_tau
¶
Kendall's tau-b between two rankings over the same labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ranks_a
|
Mapping[str, float]
|
Label to rank for the first ranking. |
required |
ranks_b
|
Mapping[str, float]
|
Label to rank for the second ranking. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The tau-b coefficient. No p-value is returned: with the four or five |
float
|
architectures compared here the smallest attainable two-sided p-value |
float
|
is |
float
|
conventional significance and reporting one would invite over-reading. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the label sets differ or fewer than three labels are given. |
Source code in deepecgkit/analysis/statistics.py
min_attainable_kendall_p
¶
Smallest two-sided p-value a tie-free Kendall's tau can attain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_labels
|
int
|
Number of ranked labels. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
float
|
four labels this is 0.083, so significance is unattainable however |
float
|
perfectly the rankings agree. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than three labels are given. |
Source code in deepecgkit/analysis/statistics.py
holm_adjust
¶
Holm step-down familywise adjustment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pvalues
|
Sequence[float]
|
Raw p-values, possibly containing NaN. |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
Adjusted p-values in the input order. |
Source code in deepecgkit/analysis/statistics.py
benjamini_yekutieli_adjust
¶
Benjamini-Yekutieli false discovery rate adjustment.
Yekutieli's correction is used rather than plain Benjamini-Hochberg because the comparisons here share training runs, models and datasets, so the positive dependence that Benjamini-Hochberg assumes is not established. The price is a factor of the harmonic number of the family size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pvalues
|
Sequence[float]
|
Raw p-values, possibly containing NaN. |
required |
Returns:
| Type | Description |
|---|---|
list[float]
|
Adjusted p-values in the input order. |
Source code in deepecgkit/analysis/statistics.py
is_bimodal
¶
is_bimodal(
values: Sequence[float],
baseline: float | None = None,
min_gap: float = MIN_COLLAPSE_GAP,
) -> tuple[bool, str]
Detect a converge-or-collapse pattern across seeds.
A mean and interval are not a summary of a bimodal sample. A model that fails to train on a subset of seeds and is competitive on the rest is a more informative finding than a wide interval, so such cells are flagged rather than averaged.
Detection keys on the largest gap between consecutive sorted values rather than on a median absolute deviation. With five seeds the deviation is far too noisy a scale estimate, and a robust-outlier rule fires on ordinary scatter; a collapse separates the sample by a wide absolute margin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Sequence[float]
|
Per-seed values of a single metric. |
required |
baseline
|
float | None
|
Optional score below which a run counts as collapsed. |
None
|
min_gap
|
float
|
Smallest separation, in metric units, that counts as a split. |
MIN_COLLAPSE_GAP
|
Returns:
| Type | Description |
|---|---|
tuple[bool, str]
|
A pair of the flag and a short reason, empty when not flagged. |
Source code in deepecgkit/analysis/statistics.py
LaTeX¶
booktabs table emitters for the seed-variance analysis.
latex
¶
booktabs table emitters for the seed-variance analysis.
Every literal containing a backslash is a raw string. Written as an ordinary string, "\toprule" is a tab followed by "oprule" and "\bottomrule" is a backspace followed by "ottomrule"; both are valid Python escapes, so neither the configured ruff rules nor W605 reports them and the emitted table silently fails to compile.
The tables need only the booktabs package, which the manuscript already loads.
escape_latex
¶
Escape the characters LaTeX treats specially.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Raw text. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Text safe to place in a table cell. |
Source code in deepecgkit/analysis/latex.py
display_model
¶
Render a registry model name for the manuscript.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registry name such as "se-resnet". |
required |
Returns:
| Type | Description |
|---|---|
str
|
The display name, escaped when unrecognised. |
Source code in deepecgkit/analysis/latex.py
display_dataset
¶
Render a registry dataset name for the manuscript.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registry name such as "af-classification". |
required |
Returns:
| Type | Description |
|---|---|
str
|
The display name, escaped when unrecognised. |
Source code in deepecgkit/analysis/latex.py
display_metric
¶
Render a metric column name for the manuscript.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Metric key such as "f1". |
required |
Returns:
| Type | Description |
|---|---|
str
|
The display name, escaped when unrecognised. |
Source code in deepecgkit/analysis/latex.py
format_cell
¶
format_cell(
mean: float,
lower: float,
upper: float,
n: int = 0,
precision: int = DEFAULT_PRECISION,
) -> str
Render a mean with its interval beneath, in the paper's style.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mean
|
float
|
Point estimate. |
required |
lower
|
float
|
Interval lower bound. |
required |
upper
|
float
|
Interval upper bound. |
required |
n
|
int
|
Number of contributing seeds. |
0
|
precision
|
int
|
Decimal places. |
DEFAULT_PRECISION
|
Returns:
| Type | Description |
|---|---|
str
|
A table cell. A single seed renders bare with no interval, because one |
str
|
run carries no dispersion; a missing value renders as a dash. |
Source code in deepecgkit/analysis/latex.py
results_table
¶
results_table(
aggregated: DataFrame,
dataset: str,
metrics: Sequence[str] = ("f1", "precision", "recall"),
label: str | None = None,
precision: int = DEFAULT_PRECISION,
confidence_level: float = 0.95,
split_description: str = SPLIT_DESCRIPTION,
) -> str
Per-dataset mean and interval table, replacing a single-run table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggregated
|
DataFrame
|
Frame from :func: |
required |
dataset
|
str
|
Dataset to render. |
required |
metrics
|
Sequence[str]
|
Metric columns in display order. |
('f1', 'precision', 'recall')
|
label
|
str | None
|
Cross-reference label. |
None
|
precision
|
int
|
Decimal places. |
DEFAULT_PRECISION
|
Returns:
| Type | Description |
|---|---|
str
|
The table as a string. Nothing is bolded: marking the best mean and |
str
|
everything whose interval overlaps it is a pairwise comparison the |
str
|
per-model intervals cannot support. Rows are ordered by the first |
str
|
metric, ascending when that metric is one where lower is better, so a |
str
|
calibration table leads with the best-calibrated model rather than the |
str
|
worst. |
Source code in deepecgkit/analysis/latex.py
rank_distribution_table
¶
rank_distribution_table(
distribution: DataFrame,
taus: DataFrame | None = None,
label: str = "tab:rank_distribution",
metric: str = "f1",
) -> str
How often each model attained each rank, per dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distribution
|
DataFrame
|
Frame from :func: |
required |
taus
|
DataFrame | None
|
Optional frame from :func: |
None
|
label
|
str
|
Cross-reference label. |
'tab:rank_distribution'
|
metric
|
str
|
Metric that was ranked, for the caption. |
'f1'
|
Returns:
| Type | Description |
|---|---|
str
|
The table as a string. |
Source code in deepecgkit/analysis/latex.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
flip_survival_table
¶
flip_survival_table(
flips: DataFrame,
label: str = "tab:flip_survival",
metric: str = "f1",
exclusions: Sequence[str] | None = None,
confidence_level: float = 0.95,
correction: str = "nadeau-bengio",
split_description: str = SPLIT_DESCRIPTION,
) -> str
The headline table: which cross-task reversals survive seed variance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flips
|
DataFrame
|
Frame from :func: |
required |
label
|
str
|
Cross-reference label. |
'tab:flip_survival'
|
metric
|
str
|
Metric that was compared, for the caption. |
'f1'
|
exclusions
|
Sequence[str] | None
|
Model or dataset restrictions to echo into the notes. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The table as a string. |
Source code in deepecgkit/analysis/latex.py
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
tau_table
¶
Supplementary Kendall's tau table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
taus
|
DataFrame
|
Frame from :func: |
required |
label
|
str
|
Cross-reference label. |
'tab:kendall_tau'
|
Returns:
| Type | Description |
|---|---|
str
|
The table as a string. |
Source code in deepecgkit/analysis/latex.py
transfer_matrix_table
¶
transfer_matrix_table(
matrix: DataFrame,
metric: str = "auroc_macro",
baseline_row: str | None = None,
label: str = "tab:transfer_matrix",
precision: int = DEFAULT_PRECISION,
) -> str
Cross-dataset linear-probe transfer matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
DataFrame
|
Frame from :meth: |
required |
metric
|
str
|
Metric filling the cells, named in the caption. |
'auroc_macro'
|
baseline_row
|
str | None
|
Index entry holding the untrained-encoder floor, moved to the top and ruled off from the trained encoders. |
None
|
label
|
str
|
Cross-reference label. |
'tab:transfer_matrix'
|
precision
|
int
|
Decimal places. |
DEFAULT_PRECISION
|
Returns:
| Type | Description |
|---|---|
str
|
The table as a string. Nothing is bolded: a single probe score carries |
str
|
no interval, so marking a best cell would assert a comparison the |
str
|
numbers cannot support. |
Source code in deepecgkit/analysis/latex.py
write_tables
¶
Write rendered tables to .tex files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tables
|
dict[str, str]
|
Mapping from stem to rendered table. |
required |
output_dir
|
Any
|
Destination directory, created if absent. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The written paths as strings. |