physioex.train.stats#
Per-subject metric aggregation (mean / std / confidence interval).
The pooled metrics computed by Trainer.evaluate / Trainer.voting_evaluate
answer “how good is the model overall”, but sleep-staging results are reported
per subject: each recording yields one score and we summarise the distribution
across subjects (mean +/- std, confidence interval). This module turns a list of
per-subject (preds, targets) tensors into those aggregates and renders a
confusion-matrix figure for logging.
Standard sleep stage labels: W=0, N1=1, N2=2, N3=3, REM=4.
Functions
|
Aggregate per-subject values into mean / std / confidence interval. |
|
Flatten an |
|
Render a confusion matrix as a matplotlib figure for logging. |
|
Render an already-computed confusion matrix tensor/array as a figure. |
|
Compute scalar and per-class metrics for each subject. |
- physioex.train.stats.aggregate(per_subject, ci_method='bootstrap', n_bootstrap=1000, ci=0.95, seed=42)[source]#
Aggregate per-subject values into mean / std / confidence interval.
Parameters#
- per_subject:
Output of
per_subject_metrics()(metric key -> list of values).- ci_method:
"bootstrap"(percentile bootstrap over subjects, robust) or"normal"(mean +/- z * std / sqrt(n)). Falls back to just the mean when fewer than two subjects are available.- n_bootstrap:
Number of bootstrap resamples (only for
ci_method="bootstrap").- ci:
Confidence level (default 0.95).
Returns#
dict mapping each metric key to
{"mean", "std", "ci_low", "ci_high", "n"}.
- physioex.train.stats.aggregated_scalars(aggregated)[source]#
Flatten an
aggregate()result into a scalar mapping for logging.Produces keys like
"eval/f1/N2/mean"and"eval/f1/N2/std"so a logger backend can record them vialog_scalars.
- physioex.train.stats.confusion_matrix_figure(preds, targets, n_classes=None, ignore_index=-1, normalize='targets', class_names=None)[source]#
Render a confusion matrix as a matplotlib figure for logging.
normalize="targets"gives per-true-class recall rows (the usual sleep hypnogram view). Returns amatplotlib.figure.Figure.
- physioex.train.stats.figure_from_cm(cm, class_names=None)[source]#
Render an already-computed confusion matrix tensor/array as a figure.
- physioex.train.stats.per_subject_metrics(preds_list, targets_list, n_classes, ignore_index=-1)[source]#
Compute scalar and per-class metrics for each subject.
Parameters#
- preds_list, targets_list:
One entry per subject.
predshas shape(n_epochs, n_classes)(logits or averaged votes);targetshas shape(n_epochs,).
Returns#
dict mapping a metric key to a list of per-subject values. Scalar metrics use their bare name (
"accuracy"); per-class metrics use"{metric}/{class_name}"(e.g."f1/N2").