From 93017021bb463fc7d090e71cfa1a69e8f210a847 Mon Sep 17 00:00:00 2001 From: ycq091044 Date: Fri, 1 Sep 2023 11:35:47 -0500 Subject: [PATCH] add docs for fairness --- docs/api/metrics.rst | 1 + docs/api/metrics/pyhealth.metrics.fairness.rst | 14 ++++++++++++++ docs/log.rst | 6 ++++++ pyhealth/metrics/fairness_utils/group.py | 2 ++ 4 files changed, 23 insertions(+) create mode 100644 docs/api/metrics/pyhealth.metrics.fairness.rst diff --git a/docs/api/metrics.rst b/docs/api/metrics.rst index 9ab65e49..c66a6c06 100644 --- a/docs/api/metrics.rst +++ b/docs/api/metrics.rst @@ -17,3 +17,4 @@ tasks, such as drug drug interaction (DDI) rate. metrics/pyhealth.metrics.binary metrics/pyhealth.metrics.calibration metrics/pyhealth.metrics.prediction_set + metrics/pyhealth.metrics.fairness diff --git a/docs/api/metrics/pyhealth.metrics.fairness.rst b/docs/api/metrics/pyhealth.metrics.fairness.rst new file mode 100644 index 00000000..a92ee91b --- /dev/null +++ b/docs/api/metrics/pyhealth.metrics.fairness.rst @@ -0,0 +1,14 @@ +pyhealth.metrics.fairness +=================================== + +.. currentmodule:: pyhealth.metrics.fairness + +.. autofunction:: fairness_metrics_fn + +.. currentmodule:: pyhealth.metrics.fairness_utils + +.. autofunction:: disparate_impact + +.. autofunction:: statistical_parity_difference + +.. autofunction:: sensitive_attributes_from_patient_ids \ No newline at end of file diff --git a/docs/log.rst b/docs/log.rst index 3f9dfc75..b5739f55 100644 --- a/docs/log.rst +++ b/docs/log.rst @@ -2,6 +2,12 @@ Development logs ====================== We track the new development here: +**Sep 01, 2023** + +.. code-block:: rst + + 1. add Base fairness metrics and example `#216`. + **July 22, 2023** .. code-block:: rst diff --git a/pyhealth/metrics/fairness_utils/group.py b/pyhealth/metrics/fairness_utils/group.py index c5543969..1a67f4f6 100644 --- a/pyhealth/metrics/fairness_utils/group.py +++ b/pyhealth/metrics/fairness_utils/group.py @@ -11,11 +11,13 @@ def disparate_impact(sensitive_attributes: np.ndarray, y_pred: np.ndarray, favor Computes the disparate impact between the the protected and unprotected group. disparate_impact = P(y_pred = favorable_outcome | P) / P(y_pred = favorable_outcome | U) + Args: sensitive_attributes: Sensitive attributes of shape (n_samples,) where 1 is the protected group and 0 is the unprotected group. y_pred: Predicted target values of shape (n_samples,). favorable_outcome: Label value which is considered favorable (i.e. "positive"). allow_zero_division: If True, use epsilon instead of 0 in the denominator if the denominator is 0. Otherwise, raise a ValueError. + Returns: The disparate impact between the protected and unprotected group. """