MaxDiffMixedLogit.apply_intervention#
- MaxDiffMixedLogit.apply_intervention(new_task_df, random_seed=None, new_respondents='error', draw_batch_size=None)[source]#
Simulate choices under a counterfactual task design.
Wraps
predict_choices()with two conveniences:Dummy
is_best/is_worstcolumns are auto-generated when both are absent fromnew_task_df(they are unused during prediction — only the item layout matters).The result is stored as
self.intervention_idatafor downstream comparison, matching the convention in the other customer-choice models.
This is the Type 1 intervention (observable attribute / assortment change). All items in
new_task_dfmust already be in the trained pool. To score new items outside the training pool usescore_new_items()(part-worths mode only).- Parameters:
- new_task_df
pd.DataFrame Counterfactual task design. Must contain
respondent_id,task_id, anditem_idcolumns.is_best/is_worstare optional — dummy flags are auto-added when both are absent.- random_seed
RandomState, optional Passed to
predict_choices().- new_respondents{“error”, “population”}, default “error”
Passed to
predict_choices().- draw_batch_size
int, optional Passed to
predict_choices().
- new_task_df
- Returns:
xr.DatasetDataset from
predict_choices()withbest_pick,worst_pick,p_best, andp_worst.
- Raises:
RuntimeErrorIf the model has not been fitted yet.