cleverly.datasets.make_heart_failure#

cleverly.datasets.make_heart_failure(n: int = 4000, *, seed: int | np.random.Generator | None = None, backend: Backend | str | None = None) → tuple[Any, pd.DataFrame][source]#

Patients sent home on a water pill with two parts, followed for readmission and death.

One row per patient, with the columns older, prior_admissions, dose, day and event. event is 1 for a readmission, 2 for a death and 0 for no event by day. A patient who left follow-up after the day-30 or day-60 check has event 0 and that day.

Parameters:
nint

Number of patients.

seedint, Generator, or None

Seed or NumPy random generator.

backend{“pandas”, “polars”, “pyarrow”} or None, default=None

Dataframe backend. None uses pandas when installed, then the first available backend.

Returns:
dataframe

The observations.

truthpandas.DataFrame

The exact risks for every pair of the dose whose fluid part a patient gets (readmission_dose) and the dose whose potassium part they get (death_dose), at each check day, with death counted first within a month: the columns readmission_dose, death_dose, day, readmission and death. A row with equal doses is the risk of that dose.

Examples

>>> from cleverly.datasets import make_heart_failure
>>> frame, truth = make_heart_failure(n=200, seed=0)
>>> list(frame.columns)
['older', 'prior_admissions', 'dose', 'day', 'event']
>>> high = truth.query("readmission_dose == 2 and death_dose == 2 and day == 90")
>>> round(float(high["death"].iloc[0]), 4)
0.361