Repository navigation
Conversation
The Colab tutorials linked from the docs had drifted from the code: three pin pyhealth==2.0a4, one trains on 26 samples from the PhysioNet demo (validation ROC-AUC 1.0) and splits by sample, the text ones train Bio_ClinicalBERT on CPU for ~25 minutes per epoch without a baseline, and none covers patient-level splitting, calibration, interpretation or medical codes. examples/tutorials/series/ adds nine notebooks with a progression of complexity, each verified end to end on CPU against master with public or synthetic data: 00 quickstart, 01 datasets, 02 tasks and processors, 03 training and evaluation (PatientSplit, pos_weight, calibration, patient bootstrap CIs), 04 choosing a model (incl. XGBoost), 05 interpreting predictions (TreeSHAP, Integrated Gradients, deletion test), 06 medical codes, 07 clinical text, 08 contributing a dataset or task. The notebooks are generated from _source/tutorials/*.py by _source/build.py (stable cell ids; --run executes them). docs/tutorials.rst lists the series first, with Colab links that open from GitHub. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Colab, installing PyHealth downgrades numpy (and pandas, pydantic) under the copies Colab already loaded, so the first import failed with "'numpy.ufunc' object has no attribute '__module__'", and pip printed a red dependency-resolver report. The install cell now installs quietly (showing pip's log only on failure), restarts the runtime once, and skips the install on the next Run all. Verified on Colab. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PyHealth's logger has its own stdout handler and also propagates to the root logger, which Colab configures, so every message printed twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Colab's free 2-CPU runtime the RNN on the heart-failure task needs ~7 minutes per epoch (long medication lists); sequence models now run only on a GPU runtime. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
07 trains one epoch on a CPU runtime (~10 minutes per epoch on Colab's free 2-CPU runtime) and recommends a GPU runtime up front; 04 no longer claims trees train much faster than the pooled neural models, which is not true on 2 CPUs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 9, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The Colab tutorials in the shared Drive folder and on the docs page have drifted from the code. I ran the five in the Drive folder against PyHealth 2.0.2, the version Colab installs today:
preprocess_<table>hooks now receive narwhals frames.pyhealth==2.0a4. A recursive PhysioNet download takes about 10 minutes and yields 26 samples, so validation ROC-AUC is 1.0 after one epoch. It splits by sample, not by patient.2.0a4. About 5 minutes per CPU epoch. Never says the synthetic notes carry no signal.2.0a4. 24 minutes for one CPU epoch, ending at macro-F1 0.009 (it predicts the majority class), with no baseline to reveal it.None of them covers patient-level splitting without leakage, imbalance, calibration, interpretation or medical codes.
What this adds
examples/tutorials/series/contains nine notebooks, in order of complexity. Each runs on a free Colab CPU runtime with public or synthetic data, so no credentials are needed.PYHEALTH_REQUIRE_CACHE_DIR), loading your own CSVs withBaseDatasetpre_filter, leak-free featuresset_task(split=PatientSplit(...))(5% of test codes are unseen in training),set_pos_weightinflates risk (0.05 → 0.45), calibration metrics, patient-levelbootstrap_ci/paired_bootstrap_diff, checkpointsXGBoostModelon one split. On Colab CPU: XGBoost PR-AUC 0.478, MLP 0.454, LR 0.384InnerMap/CrossMap, ICD-9↔ICD-10 not being a round trip, CCS/ATC groupers,code_mapping(2,528 → 257 diagnosis groups)TransformersModelsized to the hardware (Bio_ClinicalBERT for 3 epochs on GPU, small BERT for 1 epoch on CPU), a TF-IDF baseline, ICD coding as a multilabel taskpreprocess_<table>with narwhals,default_task), the metadata-table pattern for file collections, inline tests, the PR checklist* Measured on CPU (macOS, Python 3.13), excluding the install cell.
Phenotyping heart failure from an admission's medications (04, 05) is the task with real signal in the synthetic data; readmission and mortality are close to random there, and the notebooks say so where they use them.
_source/tutorials/tNN_*.pyby_source/build.py, so wording and code stay consistent and diffs stay readable. Cell ids are stable, and--runexecutes a notebook and stops at the first error.README.mdexplains how to edit them.docs/tutorials.rstlists the series first, with Colab links that open the notebooks straight from GitHub (colab.research.google.com/github/...). The older list stays below under "Earlier tutorials", so you can retire it when you like.Notes
pip install "pyhealth>=2.1"; that's one line in_source/nbkit.py, then a rebuild.numpy~=2.2,pandas~=2.3.1,pydantic~=2.11.7) downgrade packages Colab has already imported, so the firstimport pyhealthfailed ('numpy.ufunc' object has no attribute '__module__') and pip printed resolver errors. The cell now installs quietly, restarts the runtime once, and skips the install on the second Run all. Colab shows a "session crashed" notice at the restart; the Setup text says this is expected.pyhealthlogger has its own stdout handler and also propagates to the root logger, which Colab prints too. The install cell setspropagate = False.pyhealth.metrics.interpretability: the "zero" ablation multiplies code-id tensors by a float mask, so comprehensiveness and sufficiency crash for every model with code-sequence inputs; only StageNet's tuple inputs take the integer-safe path. Tutorial 05 uses a hand-written deletion test instead. This needs a small fix PR.ipywidgets, which Build datasets in notebooks without ipywidgets; fix datasets overview example #1260 fixes.split_by_patientdoes not sort patient ids before shuffling, so the same seed gives different splits in different sessions.PatientSplitdoes sort.numpy/pandas/pydanticpins above conflict with Colab's preinstalled versions. Loosening them would remove the restart.ReadmissionPredictionMIMIC3's defaultexclude_minors=Truereturns no samples. Tutorial 02 explains this and turns the option off.🤖 Generated with Claude Code