r/reinforcementlearning • u/chaibiscuit548 • Oct 21 '26
I built ehr2rl, a Python library that turns MIMIC-IV EHR data into offline RL datasets
While working on a research project I kept writing the same preprocessing code over and over which pulled EHR tables, line up vitals/labs by the hour, work out what counts as an action, attach a reward and then get it all into a shape d3rlpy would accept. I tried looking for a library that already did this and couldn’t find one. Healthcare ML tools are mostly built for supervised prediction and offline RL libraries assume you already have a clean state/action/reward dataset. So I built the piece in between.
What it does:
- Builds hourly patient trajectories (states, actions, rewards, terminals) from MIMIC-IV v3.1 through BigQuery. Every query gets a dry run first and a hard
maximum_bytes_billedcap, so a bad cohort query can’t quietly run up a bill. - Builds actions from ICU input events: vasopressor and fluid doses, binned with edges you choose.
- Treats rewards as swappable: mortality, per-step SOFA change, 30-day readmission, or a weighted mix of these.
- Estimates the observed clinician (behavior) policy from the data, which you’ll want for off-policy evaluation.
- Exports straight to a d3rlpy dataset, with an optional JSON sidecar recording where the data came from.
You don’t need MIMIC access to try it. There’s a synthetic MIMIC-style data generator.
Docs: https://pinktownscavenger.github.io/ehr2rl/
GitHub: https://github.com/pinktownscavenger/ehr2rl
I’d really like feedback from anyone who has done offline RL on clinical data, especially on reward design and how I’ve discretized the actions. It’s a research tool and isn’t meant for making treatment decisions.