K-Dense-AI/scientific-agent-skills / skills/pyhealth
pyhealth
VerifiedBuilds and validates PyHealth clinical machine-learning pipelines for EHR, signals, imaging, and medical codes. Use for PyHealth dataset loading, MIMIC-III/IV, eICU or OMOP prediction tasks, patient-level evaluation, mortality/readmission/length-of-stay modeling, medication recommendation, sleep staging, Trainer checkpoints, and ICD/ATC/NDC/RxNorm mapping.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 8.0 KB |
| assets/starter_pipeline.py | script | 3.8 KB |
| references/datasets.md | markdown | 5.2 KB |
| references/examples.md | markdown | 6.9 KB |
| references/installation.md | markdown | 4.4 KB |
| references/medcode.md | markdown | 3.6 KB |
| references/models.md | markdown | 5.8 KB |
| references/tasks.md | markdown | 6.5 KB |
assets/starter_pipeline.py
View on GitHub"""PyHealth 2.0.2 CPU starter: --demo or --root <MIMIC-III directory/URL>.
The demo has invented codes and labels: it checks plumbing, not clinical validity.
Real-data mode uses the upstream next-visit mortality task, not early warning.
"""
import argparse
from pathlib import Path
def build_samples(root=None, cache_dir=None, dev=False):
from pyhealth.datasets import MIMIC3Dataset, create_sample_dataset
from pyhealth.tasks import MortalityPredictionMIMIC3
task = MortalityPredictionMIMIC3()
if root is not None:
base = MIMIC3Dataset(
root=root,
tables=["diagnoses_icd", "procedures_icd", "prescriptions"],
cache_dir=cache_dir,
dev=dev,
num_workers=1,
)
return base.set_task(task)
records = [
{
"patient_id": f"demo-{i}",
"visit_id": f"demo-{i}-{j}",
"conditions": ["invented-condition", f"group-{i % 3}"],
"procedures": ["invented-procedure"],
"drugs": ["invented-drug"],
"mortality": (i + j) % 2,
}
for i in range(60)
for j in range(2)
]
return create_sample_dataset(
records, input_schema=task.input_schema, output_schema=task.output_schema
)
def train_and_evaluate(samples, output_path, epochs=1, seed=42):
import random
import numpy as np
import torch
from pyhealth.datasets import get_dataloader, split_by_patient
from pyhealth.models import Transformer
from pyhealth.trainer import Trainer
if epochs < 1:
raise ValueError("epochs must be positive")
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.set_num_threads(1)
parts = split_by_patient(samples, [0.6, 0.2, 0.2], seed=seed)
patient_sets = [set(part.patient_to_index) for part in parts]
for i in range(3):
for j in range(i):
if patient_sets[i] & patient_sets[j]:
raise ValueError("Patient overlap between partitions")
for name, part in zip(("train", "validation", "test"), parts):
if len(part) == 0:
raise ValueError(f"Empty {name} partition")
labels = {int(part[i]["mortality"].item()) for i in range(len(part))}
if labels != {0, 1}:
raise ValueError(f"{name} needs both binary classes for ROC AUC")
loaders = [
get_dataloader(part, batch_size=16, shuffle=(i == 0))
for i, part in enumerate(parts)
]
model = Transformer(dataset=parts[0], embedding_dim=16, dropout=0.0)
trainer = Trainer(
model=model,
metrics=["pr_auc", "roc_auc", "f1"],
device="cpu",
output_path=str(output_path),
exp_name="starter",
)
trainer.train(
train_dataloader=loaders[0],
val_dataloader=loaders[1],
epochs=epochs,
monitor="pr_auc",
monitor_criterion="max",
patience=5,
)
scores = trainer.evaluate(loaders[2])
return trainer, scores
def main():
parser = argparse.ArgumentParser(description=__doc__)
source = parser.add_mutually_exclusive_group(required=True)
source.add_argument("--demo", action="store_true", help="Use invented in-memory data")
source.add_argument("--root", help="Local or public MIMIC-III root")
parser.add_argument("--cache-dir", type=Path, default=Path("cache/mimic3"))
parser.add_argument("--output", type=Path, default=Path("output/pyhealth"))
parser.add_argument("--epochs", type=int, default=1)
parser.add_argument("--dev", action="store_true", help="Limit raw data to 1000 patients")
args = parser.parse_args()
samples = build_samples(args.root, args.cache_dir, args.dev)
_, scores = train_and_evaluate(samples, args.output, epochs=args.epochs)
print("[OK]", scores)
if __name__ == "__main__":
main()
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |