alterlab-pyhealth
Installation
SKILL.md
PyHealth: Healthcare AI Toolkit
Overview
PyHealth is a Python library for healthcare AI that provides datasets, task definitions, models, trainers, and medical-code utilities for clinical machine learning. Use this skill when developing healthcare prediction models, processing clinical data, working with medical coding systems, or validating models before any clinical use.
Version gotcha (read first). This skill targets PyHealth 2.x (current release 2.0.2, Sept 2026). The 2.0 rewrite changed the API in ways most tutorials and pre-2025 snippets get wrong:
- Tasks are classes you instantiate, e.g.
MortalityPredictionMIMIC4(),DrugRecommendationMIMIC3()— not the old snake-casemortality_prediction_mimic4_fnfunctions. Pass the instance todataset.set_task(task).- Datasets take an explicit table list. Single-source loaders use
root=+tables=[...](MIMIC3Dataset,MIMIC4EHRDataset,eICUDataset,OMOPDataset); the multimodalMIMIC4Datasetusesehr_root=+ehr_tables=[...](plus optionalnote_root/cxr_root).- Models take only the
SampleDatasetplus hyperparameters, e.g.Transformer(dataset=samples, embedding_dim=128). Feature keys, label key, and mode are read from the task'sinput_schema/output_schema; the 1.xfeature_keys=/label_key=/mode=arguments raiseTypeError.- Metric names have no
_scoresuffix:pr_auc,roc_auc,f1; multilabel/drug-rec use the*_samplesfamily (jaccard_samples,f1_samples,pr_auc_samples). Passmetrics=[...]to theTrainerconstructor andmonitor=one of those names.- Checkpoints use
trainer.save_ckpt(path)/trainer.load_ckpt(path)(there is notrainer.save).- 2.0.2 requires Python 3.12 or 3.13 and pins its own stack (numpy 2.2, pandas 2.3, torch 2.7, transformers 4.53), so install it in a dedicated environment rather than next to pandas 3 / transformers 5.
When unsure of a class or argument name, check the installed source rather than trusting older snippets.
When to Use This Skill
Invoke this skill when: