cleverly.datasets.make_treatment_rules#

cleverly.datasets.make_treatment_rules(n: int = 2000, *, seed: int | Generator | None = None, backend: Literal['pandas', 'polars'] | str | None = None) → tuple[Any, dict[str, float]][source]#

Draw the navigation program whose offer helps high-need patients and not low-need ones.

Parameters:
nint, default=2000

The 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

One row per patient, with the columns need, lives_alone, offer and home_30.

truthdict of str to float

The share who stay home for 30 days had every patient been offered navigation (ey_all), had none been (ey_none), and under the best rule (ey_best_rule), each exact; their difference ate (ey_all - ey_none); and best_rule_cutoff, the need score above which the best rule offers navigation.

See also

cleverly.datasets.treatment_rule_value

The exact value of any other offer policy.

cleverly.datasets.learned_rule_truth

The true value of the rules a learned-rule fit used.

Examples

>>> from cleverly.datasets import make_treatment_rules
>>> frame, truth = make_treatment_rules(n=5, seed=0)
>>> list(frame.columns)
['need', 'lives_alone', 'offer', 'home_30']
>>> round(truth["ey_best_rule"] - truth["ey_all"], 4)
0.0434