Repository navigation
Add ClinicalPresenceMortalityMIMIC3 task and capacity-based fairness metrics (Jeanselme et al., ML4H 2022) - #1557
Conversation
Test CoverageTotal: 87.55% (52981 / 60516 lines)
|
1743205 to
4a0a9b1
Compare
|
/review |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: need change
decision: human review
Thank you for this contribution, Chunyi and John. It adds a reproducible version of the Jeanselme et al. MIMIC-III experiment: a ClinicalPresenceMortalityMIMIC3 task with several imputation strategies, a capacity-based fairness metric that matches the reference bootstrap, an example script with results, docs, and 47 synthetic-data tests. It is carefully done and thoroughly documented. Coverage is above the bar: 100% for capacity.py, 98.84% for the task file, and 86.11% for the whole repository.
To get this merged:
- The example
examples/mimic3_clinical_presence_mortality_logistic_regression.pyimports the private helper_bootstrapfrompyhealth/metrics/fairness_utils/capacity.py. It uses it inpaired_differencesto reuse the metric's resampling. The description doesn't mention this link. Please do one of these: confirm the sharing is intended and say why in the description (for example, the paired bootstrap needs the same resamples ascapacity_fairness_metrics), or keep the example self-contained, by copying the few lines it needs or calling the public function.
Optional suggestions:
- The task docstring says the group flags are "never features". Group MICE does use them as imputation predictors, so they reach the classifier indirectly. A short sentence saying so would be clearer.
- The example script is about 1,400 lines. Moving the report and plotting code into helpers or a separate file would make it easier to review. The script itself has no tests, so that is worth noting too.
- On your question about
pyhealth.metrics: that is a maintainer call. Re-exporting there would be a simple registration.
I haven't run the code, so the numbers in the results file are unchecked.
Reviewed commit 4a0a9b1
|
/review Generated by Claude Code |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: approve
decision: human review
Thank you, Chunyi and John, for this contribution. It adds a reproducible task for the Jeanselme et al. clinical-presence experiment, a capacity-based fairness metric that matches the reference evaluate() to 12 decimals, an example script and a results write-up.
This looks ready to merge. The task and the metric are self-contained. The __init__.py edits only add exports, and nothing existing is renamed or rebound. The task imports only BaseTask and Patient, so there are no undeclared links between components. The task cites its paper and the MIMIC-III source. The docs match the code, and the differences from the reference are listed clearly.
Coverage meets the bar. The whole repository is at 86.2%, which is above 60%. The new files are at 98.8% (task) and 100% (metric), which is above 80%.
Optional suggestions:
- The task docs page (about 280 lines) repeats much of the class docstring and the results
.md. You could shorten it, for example by keeping the strategies table and the differences table and linking to the results file for the rest. - The example script is long (about 1,400 lines). Moving the report and plotting helpers into a separate module would make it easier to read.
- The results file says PyHealth 2.0.2 for the main run. A short note on whether anything changed in 2.1.0 would help readers who reproduce it.
- On your question about exporting
capacity_fairness_metricsfrompyhealth.metrics: that is up to the maintainers.
Reviewed commit bece67c
bece67c to
a775c99
Compare
|
Pushed a rebase to resolve a merge conflict. |
|
/review |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: approve
decision: human review
Thank you, Chunyi and John, for this contribution. It adds a task that reproduces the Jeanselme et al. MIMIC-III experiment (cohort-level imputation, 8-day mortality), plus a capacity-based fairness metric, an example script with results, and docs.
It looks ready to merge. The task and the metric are self-contained. The only edits to existing files are two exports in __init__.py and docs entries, which count as registration. The description names the paper and reference code, lists every difference from the reference, and states the limitations. The metric is checked against the reference's evaluate() to 12 decimals. The 47 tests cover the cohort rules, split, imputers, train-only fitting, set_task end to end, the metric's hand-computed values and its error cases.
Coverage is above the bar. The whole repo is at 87.22%. capacity.py is at 100% and the task file at 98.84%. The two modified __init__.py files are at 100% and 98.29%.
Optional suggestions:
- The task docs page (about 280 lines) and the example script (about 1,300 lines) are long. You could trim the docs to the essentials and link to the results
.mdfor the rest. from sklearn.experimental import enable_iterative_imputerruns at import ofpyhealth.tasks. You could import it lazily inside_make_imputer, so other users ofpyhealth.tasksdon't pay for it.- With
num_workersabove 1, the fitted feature arrays (up to about 195 MB) are pickled to each worker. A short note in the docs would help. - On your question about exporting
capacity_fairness_metricsfrompyhealth.metrics, a maintainer can decide that.
Reviewed commit a775c99
|
Good news: this PR has moved from One step is left. The AI review doesn't review a commit twice, so please push a new commit (rebasing on master is enough) and then comment |
… verify data integrity
…d for imputation, and the imputer has a sample run mode.
…dized to its own training statistics.
1. Extreme imputation count inflated due to imputed float32 values with float64 bounds. A lab with one trianing value causes imputed values to fall out of bounds, making this type mismatch matter. 2. Reduce amount of logging, only keeping the base log.txt. 3. Fix figure titles.
… expeirments, utilizing the indicators before imputation.
…skip regression when there are no missing training values.
…nge generic var names to be specific. Remove inline logic.
… we use this helper.
a775c99 to
b1ce58f
Compare
|
/review |
| "max_iter": max_iter, | ||
| "initial_strategy": "median", | ||
| "imputation_order": "ascending", | ||
| "keep_empty_features": True, |
There was a problem hiding this comment.
[low] Labs never observed in training rows are left unscaled in val/test
With keep_empty_features=True, scikit-learn's imputers fill a lab that is all-NaN in the fitted rows with 0. The scaler in _assemble then sees a constant zero column and uses scale 1. Any val or test patient who does have that lab keeps the raw value, so it enters the classifier unstandardised, which contradicts the docs ("every column is standardised on the training patients"). This needs a lab with no training observations but some validation or test observations, so it is unlikely on MIMIC-III, but the docs promise otherwise. Fix: mask such labs out of the features, or set their scaled values to 0 for all rows, and add a test where a lab is observed only outside the training rows.
| ) | ||
| black = pl.col("ethnicity").str.contains("BLACK", literal=True).fill_null(False) | ||
| female = (pl.col("gender") == "F").fill_null(False) | ||
| public_insurance = (pl.col("insurance") != "Private").fill_null(True) |
There was a problem hiding this comment.
[low] Null insurance is counted as public, and the docs do not say so
fill_null(True) makes a patient with a missing insurance value public_insurance = 1. The docs say the flag is "any insurance other than Private", which does not cover null. Either document the null case, or treat null as unknown and exclude it from the fairness comparison.
| @@ -0,0 +1,1406 @@ | |||
| r"""Imputation strategies and fairness on MIMIC-III (Jeanselme et al., ML4H 2022). | |||
There was a problem hiding this comment.
[low] Example is about 1,400 lines, mostly report generation
The script adds plotting, markdown report writing, paired bootstraps and the order comparison on top of the experiment. Much of this is beyond what PyHealth's examples usually carry. Moving the report and plotting code out, or dropping the paired-bootstrap and figure parts, would make the experiment easier to follow. The results file already documents the outputs, so this does not block the merge.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: approve
Thank you for this contribution. It adds a task that reproduces the MIMIC-III experiment of Jeanselme et al. (ML4H 2022), and a capacity-based fairness metric that matches the reference evaluate to 12 decimals. It also adds an example script, a results write-up, docs and 47 synthetic-data tests. It looks ready to merge.
Checks:
- Self-contained: the task uses only
BaseTask,Patientand third-party libraries. The only edits to shared files are the new export lines in two__init__.pyfiles. They are registration only, and no existing export is removed, renamed or rebound. - Citations: the paper and the reference code are cited in the docstrings and docs. No new dataset is added.
- Docs: the differences from the reference code, the limitations and the sample schema are clearly documented and match the code.
- Coverage: the whole repository is at 87.55%, against the 60% bar.
capacity.pyis at 100% andclinical_presence_mortality_mimic3.pyis at 98.84%, both above the 80% bar.
Optional suggestions:
- A lab with no training observations but some validation or test observations seems to keep its raw, unscaled values. Please check this, and note it in the docs if it is intended.
- Say in the docs that a null insurance value is counted as public insurance.
- The 1,400-line example holds a lot of report-building code. You could trim it or move part of it out, but this is not required.
- On your question about
pyhealth.metrics: exportingcapacity_fairness_metricsthere is reasonable if it matchesfairness_metrics_fn. That is the maintainers' call.
Reviewed commit b1ce58f
Contributor: Chunyi Yu (cyu410@gatech.edu) and John Nguyen (jnguyen461@gatech.edu), Georgia Tech, CSE 6250 (Fall 2026)
Contribution Type: Standalone Task, with a fairness metric
Paper: Jeanselme, De-Arteaga, Zhang, Barrett and Tom. "Imputation Strategies Under Clinical Presence: Impact on Algorithmic Fairness." ML4H 2022, PMLR 193:12–34. https://proceedings.mlr.press/v193/jeanselme22a.html. Reference code: https://github.com/Jeanselme/ClinicalPresenceFairness (MIT).
Description: Missing data in electronic health records indicates both the patient's access to care and their health. Consequently, missingness can be used as an indicator between groups of patients. Jeanselme et al. shows that imputation strategies with similar population AUC can still treat marginalised groups differently. This PR makes its MIMIC-III experiment reproducible in PyHealth:
ClinicalPresenceMortalityMIMIC3builds the paper's cohort (each adult's last admission of at least 24 h, the latest value of 67 labs in its first 24 h, death within 8 days) and imputes the labs at the cohort level. Strategies: Median, MICE and Group MICE, each with optional missingness indicators, plus MissForest-style imputation as an ablation and a corrected MICE as a sensitivity analysis. Black, female and public-insurance flags travel with each sample for evaluation only.capacity_fairness_metricscompares a group with the rest when only the topcapacityshare of risk scores is prioritised. It reports AUC, prioritisation rate, FNR and FPR, and their gaps, bootstrapped as in the paper..mdfile next to it.No MIMIC-III data is included. The tests use synthetic patients.
Files to Review:
pyhealth/tasks/clinical_presence_mortality_mimic3.py- the task (start withpre_filter)pyhealth/metrics/fairness_utils/capacity.py- the metricexamples/mimic3_clinical_presence_mortality_logistic_regression.py- the experimentexamples/mimic3_clinical_presence_mortality_logistic_regression.md- our results on MIMIC-III v1.4tests/core/test_clinical_presence_mortality_mimic3.py,tests/core/test_fairness_capacity.py- testsdocs/api/tasks/pyhealth.tasks.ClinicalPresenceMortalityMIMIC3.rst,docs/api/metrics/pyhealth.metrics.fairness.rst- docs, with their toctree entries and the two__init__.pyexportsDesign
pre_filter, the only hook that sees the whole cohort. By default each imputer is fit on the training patients only, so validation and test patients cannot shift the training values.__call__is then a lookup.splitanddrawfields. The split depends only on cohort and seed, so every strategy is evaluated on the same test patients.Differences from the reference code
The task follows the reference code, which produced the paper's numbers, except where the code has a bug or departs from the paper's text. The task's docs page lists each difference and its effect.
reference_split=Truere-creates its split.indicators_in_imputation=Truegives the code's order.DEATHTIMEandHADM_ID, which PyHealth's config did not load when the task was written.Results
On MIMIC-III v1.4 and run over five split seeds. The results file has the full tables, the hypotheses and the ablations.
Verification
PYHEALTH_RUN_SLOW=1.evaluate()to 12 decimal places.tools/check_pr_rules.py).Limitations
LogisticRegressionis the library-native path, not the paper's ℓ2 model, and its results depend on the sample cache's order.Notes from the authors
Possible follow-ups
deathtimeandlabevents.hadm_id.Question for maintainers
Should
capacity_fairness_metricsalso be importable frompyhealth.metrics, likefairness_metrics_fn?