{# REVIEW: the wording of this section was written by the builder, not by the author. #} {# A schematic, not data: three hospitals, two slides each, every slide cut into nine patches. In hospital 0 both slides belong to one patient. The cells drawn as test show which unit each way of holding data out keeps away from training. #} {% macro split_diagram(level) %} {% for h in range(3) %} {% set hx = 2 + h * 61 %} {% for sl in range(2) %} {% set sx = hx + 5 + sl * 25 %} {% for c in range(9) %} {% set test = (level == 'patch' and (h * 11 + sl * 7 + c * 5) % 4 == 0) or (level == 'slide' and ((h == 0 and sl == 1) or (h == 1 and sl == 0))) or (level == 'patient' and h == 0) or (level == 'hospital' and h == 2) %} {% endfor %} {% endfor %} hospital {% endfor %} {% endmacro %} {% set split_text = { "patch": "Random patches are held out. Their neighbors from the same slide stay in training.", "slide": "Whole slides are held out. A patient's other slide can still be in training.", "patient": "All slides of a patient are held out together.", "hospital": "A whole hospital is held out, so every test patch comes from a lab never seen in training." } %}

Four ways to count one

Each slide is cut into thousands of small patches, and the network sees one patch at a time. Patches from one slide look alike, so a test patch whose neighbors were in training makes an easy test. The four ways below differ only in which unit is kept out of training.

{% for r in p2.lvtable %}
By {{ r.level }}
{{ split_diagram(r.level) }}

{{ split_text[r.level] }}

{{ r.auroc|num(3) }} pooled AUROC

{% endfor %}

training test two slides from one patient Schematic, not to scale: each small square is a patch, each block of nine a slide, each box a hospital.

The same network was trained for each of {{ p2.levels.levels|length|count }} ways of holding data out, {{ p2.n_folds|count }} times each, so that a different fifth of the data was the test set every time, and every patch was predicted exactly once. The figure shows the pooled AUROC with a {{ p2.ci_level|pct(0) }} interval that resamples slides, not patches.

Top: pooled AUROC for each level; the vertical bar is the interval, the short gray ticks to the left are the individual folds. Bottom: the hospital level, one point per held-out hospital, with intervals that resample that hospital's slides. Plain models, first seed.
{% for r in p2.lvtable %} {% endfor %}
The numbers behind the figure
Held outPooled AUROCInterval (slides)AccuracyMean of the fold AUROCsFold range
{{ r.level }}{{ r.auroc|num(4) }}{{ r.ci|ci(4) }}{{ r.acc|pct(1) }}{{ r.fold_mean|num(4) }}{{ r.fold_min|num(3) }} to {{ r.fold_max|num(3) }}

Patch level, resampling patches instead of slides, gives the narrower interval {{ p2.patch_row_ci|ci(4) }}. That interval treats neighboring patches as independent, which they are not, so the slide interval is the one to trust.

Caveats