Policy¶
See Behavior policy for which action is modeled and how to model both medication columns.
- class ehr2rl.BehaviorPolicy(n_action_bins=5, random_state=42)¶
Estimate the probability of each observed action given the state.
Only the first action column is modeled. Integer actions with at most
n_action_binsdistinct values are used as classes directly; other actions are split into at mostn_action_binsquantile bins.- Parameters:
- fit(dataset)¶
Fit the policy on every timestep of a dataset.
Trains a standardized multinomial logistic regression, or a constant classifier when only one action class is observed.
- Parameters:
dataset (
EHRDataset) – Non-empty dataset.- Returns:
This policy, for chaining.
- Return type:
- Raises:
ValueError – If the dataset is empty.
- predict_proba(states)¶
Return the probability of each action class for each state.
- Parameters:
states (
ndarray) – Shape(N, D).- Returns:
Shape
(N, n_classes). Columns followmodel.classes_.- Return type:
- Raises:
ValueError – If the policy has not been fit.
- propensity_scores(dataset)¶
Return the probability of the action actually taken at each timestep.
An action class not seen during
fitgets the first class’s probability.- Parameters:
dataset (
EHRDataset) – Dataset to score, with the same action encoding used for fitting.- Returns:
Shape
(N,), whereNis the total number of timesteps.- Return type:
- Raises:
ValueError – If the policy has not been fit or the dataset is empty.