py-why / py-why/EconML

Can Dynamic Double Machine Learning use SHAP?

Open
#761 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
4.8k
Forks
827
PR merge metrics
No merged PRs in 30d

Description

When there is only one panel, it works fine, but multiple panels will report “list index out of range”.for exmaple

Define DGP parameters

np.random.seed(123)
n_panels = 5000 # number of panels
n_periods = 3 # number of time periods in each panel
n_treatments = 3 # number of treatments in each period
n_x = 100 # number of features + controls
s_x = 10 # number of controls (endogeneous variables)
s_t = 10 # treatment support size

Generate data

Define additional DGP parameters

het_strength = .5
het_inds = np.arange(n_x - n_treatments, n_x)

Generate data

dgp = DynamicPanelDGP(n_periods, n_treatments, n_x).create_instance(
s_x, hetero_strength=het_strength, hetero_inds=het_inds, random_seed=12)
Y, T, X, W, groups = dgp.observational_data(n_panels, s_t=s_t, random_seed=1)
ate_effect = dgp.true_effect
het_effect = dgp.true_hetero_effect[:, het_inds + 1]
#%%

est = DynamicDML(
model_y=RandomForestRegressor(),
model_t=RandomForestRegressor(),cv=3)
est.fit(Y, T, X=X, W=W, groups=groups, inference="auto")
#%%
import shap

explain the model's predictions using SHAP values

shap_values = est.shap_values(X, feature_names=['A', 'B', 'C'], background_samples=100)
shap.summary_plot(shap_values['Y0']['T0'])

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the DynamicDML.shap_values entry point and reproduce the reported example with one panel and multiple panels using the shown SHAP call. Trace the “list index out of range” failure in the multi-panel case; done means the call returns SHAP values that can be passed to shap.summary_plot for multiple panels.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.