{ "cells": [ { "cell_type": "markdown", "id": "c00", "metadata": {}, "source": [ "# A training cohort with a study-level split\n", "\n", "A model trained on spatial data should be tested on data from experiments it has not seen. If sections from the\n", "same experiment end up in both the training and the test fold, the test score measures how well the model\n", "recognises that experiment, not how well it generalises. The notebook builds a small cohort for training, splits\n", "it so that each experiment stays in one fold, reads one table per fold and records the split so that it can be\n", "reproduced.\n", "\n", "It uses the steps from the tutorials, mainly {doc}`../tutorials/03_cohorts_and_manifests`, and adds\n", "`split()` and the `TableAdapter` interface. The cohort is small (five Visium sections of human pancreatic\n", "tumours, of which only the tables are read), so it runs on a laptop." ] }, { "cell_type": "code", "execution_count": 1, "id": "c01", "metadata": { "execution": { "iopub.execute_input": "2026-10-31T23:40:11.436598Z", "iopub.status.busy": "2026-10-31T23:40:11.436231Z", "iopub.status.idle": "2026-10-31T23:40:12.678096Z", "shell.execute_reply": "2026-10-31T23:40:12.676753Z" } }, "outputs": [], "source": [ "import tempfile\n", "from pathlib import Path\n", "from typing import Any\n", "\n", "import sddb\n", "from sddb import SplitManifest, SpatialDataCohort, TableAdapter\n", "\n", "cat = sddb.Catalog(version=\"2026-10-28\")\n", "work = Path(tempfile.mkdtemp()) # the files this notebook writes go here" ] }, { "cell_type": "markdown", "id": "c02", "metadata": {}, "source": [ "## The cohort\n", "\n", "Five Visium sections of human pancreatic ductal adenocarcinoma from three GEO series. The `collections` column\n", "names the series of each section." ] }, { "cell_type": "code", "execution_count": 2, "id": "c03", "metadata": { "execution": { "iopub.execute_input": "2026-10-31T23:40:12.682203Z", "iopub.status.busy": "2026-10-31T23:40:12.681952Z", "iopub.status.idle": "2026-10-31T23:40:12.698488Z", "shell.execute_reply": "2026-10-31T23:40:12.697444Z" } }, "outputs": [ { "data": { "text/html": [ "
| \n", " | uid | \n", "study_id | \n", "collections | \n", "n_obs | \n", "n_features | \n", "
|---|---|---|---|---|---|
| 0 | \n", "qEP9pd4LlyKeufe20000 | \n", "geo:GSM8915497 | \n", "[geo-gse294669] | \n", "1142 | \n", "17943 | \n", "
| 1 | \n", "0877Bxvk1AFUpoD90000 | \n", "geo:GSM8641038 | \n", "[geo-gse282302] | \n", "2261 | \n", "19144 | \n", "
| 2 | \n", "Mc06lamGrOTYHhNF0000 | \n", "geo:GSM8714181 | \n", "[geo-gse274557] | \n", "419 | \n", "36601 | \n", "
| 3 | \n", "URKDREjVhAsRwwF10000 | \n", "geo:GSM8714178 | \n", "[geo-gse274557] | \n", "660 | \n", "36601 | \n", "
| 4 | \n", "StreGVL1Uyj2EeoM0000 | \n", "geo:GSM8641015 | \n", "[geo-gse282302] | \n", "2302 | \n", "19144 | \n", "