跳到正文

PyHealth 临床机器学习研究

使用 PyHealth 组织电子病历、信号和医疗编码的研究处理与模型评估,核查输入、目标、处理流程和适用限制。

开源精选医疗业务11 个文件50,135 Stars浏览次数 2K-Dense-AI/scientific-agent-skills MIT版本 a1043ef
开始使用

适用环境:Requires Python 3.12 or 3.13 and PyHealth 2.0.2 (Torch 2.7.1). Network access is needed for installation, public datasets and uncached medical-code resources. Restricted clinical datasets require authorized local access.

输入资料
获准使用的研究数据与任务定义 PyHealth 环境及研究评价要求 阅读本节完整说明
交付内容
可复查的研究流程 模型评价与数据处理记录 阅读本节完整说明
  1. 获取完整包,保留配套文件的目录结构。
  2. 按照原文准备所需工具、依赖与输入资料。
  3. 阅读对应使用步骤与输入输出说明,在自己的环境中验证结果。

使用提示摘自原文,配套文件保留来源版本;实际运行条件以各包说明为准。

正文

获取原文件

references/tasks.md

The following exports were checked in PyHealth 2.0.2. A name identifies a task implementation, not proof that its cohort/outcome matches a proposed study. Inspect task.input_schema, task.output_schema and raw task(patient) output before running base.set_task(task).

Common clinical tasks

Task Data Key implementation details
MortalityPredictionMIMIC3, MortalityPredictionMIMIC4 MIMIC-III/IV Current-visit conditions/procedures/drugs -> mortality: binary in next visit; requires a future admission
InHospitalMortalityMIMIC4 MIMIC-IV labs First 48 hours' selected labs; adults and stays longer than 48 hours; labs: timeseries -> mortality: binary
MortalityPredictionEICU, MortalityPredictionEICU2, MortalityPredictionOMOP Matching source Inspect source-specific mortality semantics and missing labels; they are not interchangeable with MIMIC
ReadmissionPredictionMIMIC3, ReadmissionPredictionMIMIC4, ReadmissionPredictionOMOP Matching source readmission: binary; default window=timedelta(days=15), not a universal 30-day outcome
ReadmissionPredictionEICU eICU Different constructor/ICU-stay logic; no MIMIC-style window argument
LengthOfStayPredictionMIMIC3, LengthOfStayPredictionMIMIC4, LengthOfStayPredictioneICU, LengthOfStayPredictionOMOP Matching source los: multiclass; spelling of eICU differs from other class names
DrugRecommendationMIMIC3, DrugRecommendationMIMIC4, DrugRecommendationEICU, DrugRecommendationOMOP Matching source Historical inputs -> current medication set; inspect source-specific drug vocabularies
MortalityPredictionStageNetMIMIC4 MIMIC-IV StageNet-oriented feature preparation
DKAPredictionMIMIC4 MIMIC-IV DKA-specific cohort and label construction
MIMIC3ICD9Coding MIMIC-III notes Discharge-note ICD-9 coding, not early risk prediction

For MIMIC mortality/readmission/LOS, load all three selectors: diagnoses_icd, procedures_icd, prescriptions. Missing one may cause all visits to be excluded. The LOS implementation uses whole-visit codes and prescriptions: using it unchanged to claim admission-time prediction would leak future information. Its ten categories are <1 day, integer days 1 through 7, days 8 through 14, and >14; MIMIC uses whole elapsed days.

MIMIC readmission excludes the last observed admission and normally minors. The label compares next admission with current discharge using a strict < window. This selected cohort is not all discharges with complete follow-up; address censoring, transfers/overlaps, and patients without another recorded admission explicitly. The next-visit MIMIC-III mortality task maps an invalid/missing future mortality flag to zero: unknown status is not necessarily survival. Audit or override that behavior.

The MIMIC-IV in-hospital task also checks lab storetime <= prediction_time, beyond measurement time. Keep that availability filter. The MEDS mortality task has a separate contract; do not transfer its exact parameters to the MIMIC-IV task.

Signals, images, text and other tasks

Export Dataset/task
SleepStagingSleepEDF SleepEDF: signal: tensor -> label: multiclass; 30-second chunks by default
EEGEventsTUEV, EEGAbnormalTUAB TUEV event / TUAB abnormality classification
COVID19CXRClassification COVID19CXR multiclass
ChestXray14BinaryClassification, ChestXray14MultilabelClassification One disease versus multi-disease ChestXray14 targets
cardiology_isAR_fn, cardiology_isBBBFB_fn, cardiology_isAD_fn, cardiology_isCD_fn, cardiology_isWA_fn Legacy callable cardiology tasks; do not assume a BaseTask schema
MedicalTranscriptionsClassification, DeIDNERTask Specialty classification / clinical de-identification
VariantClassificationClinVar, MutationPathogenicityPrediction ClinVar/COSMIC labels
CancerSurvivalPrediction, CancerMutationBurden TCGA-PRAD outcomes
BenchmarkEHRShot EHRShot benchmark labels

SleepStagingSleepEDF 2.0.2 retains six labels W/N1/N2/N3/N4/REM. It does not silently merge N3 and N4 into the common five-class convention. Declare any remapping and validate EDF channels, sample rate, annotation boundaries and patient/night grouping. Other dataset recipes in this table are source-verified inventories, not executed clinical or signal experiments.

Metrics

Output mode Example metrics / monitor names
Binary pr_auc, roc_auc, f1
Multiclass accuracy, f1_macro, cohen_kappa
Multilabel pr_auc_samples, jaccard_samples, f1_samples

A metric's averaging policy matters; sample-wise multilabel metrics are not the only valid choice. Inspect rare/absent classes, label coverage and decision thresholds. PR-AUC of 0.5 has different meaning at 1% and 50% prevalence. Set the monitor to an actual validation score key and specify monitor_criterion.

Custom tasks use events in 2.x

Illustrative MIMIC-III adapter below keeps the built-in feature extraction but excludes samples whose future mortality flag is unknown. This solves only that missing-label issue; it retains the built-in next-admission cohort and feature timing.

from pyhealth.tasks import MortalityPredictionMIMIC3

class KnownNextVisitMortality(MortalityPredictionMIMIC3):
    task_name = "KnownNextVisitMortality"

    def __call__(self, patient):
        admissions = patient.get_events(event_type="admissions")
        known = {
            current.hadm_id
            for current, future in zip(admissions, admissions[1:])
            if future.hospital_expire_flag in (0, 1, "0", "1")
        }
        return [s for s in super().__call__(patient) if s["hadm_id"] in known]

For a new outcome, subclass BaseTask, declare input/output schemas, and implement __call__(patient) returning dictionaries with patient/record IDs plus all schema fields. [] excludes a patient. Use get_events(event_type=..., start=..., end=..., filters=[(...)]); the 2.x Patient has no visits or next_visit API. Define lab thresholds, units, missingness, observation time and censoring in the task itself. Give changed task implementations new cache identities or fresh cache roots.

Sources: tasks, released package.

CONTACT HAONAN

联系haonan

医疗 AI · 产品与独立开发

刘浩南

关注医疗 AI 从 demo 到真实落地,聚焦产品化、商业化与院内工作流效率提升。

12年医疗产研经验,大湾区头部医疗AI公司前产品总监,独立开发者

医疗 AI 产品化医疗 AI 商业化院内工作流效率
刘浩南的微信联系二维码
微信扫一扫,联系 haonan