matheusfacure / python-causality-handbook

Causal Inference for the Brave and True. A light-hearted yet rigorous approach to learning about impact estimation and causality.
https://matheusfacure.github.io/python-causality-handbook/landing-page.html
MIT License
2.65k stars 463 forks source link

Issue on page /21-Meta-Learners.html #262

Closed kevin-mercurio closed 1 year ago

kevin-mercurio commented 2 years ago

The implementation of the final estimator is slightly off relative to the publication:

x_cate_train = (ps_predict(train,0)mx0.predict(train[X]) + ps_predict(train,1)mx1.predict(train[X]))

x_cate_test = test.assign(cate=(ps_predict(test,0)mx0.predict(test[X]) + ps_predict(test,1)mx1.predict(test[X])))

The propensity score should actually be swapped, such that your estimators are:

def ps_predict(df, t): return g.predict_proba(df[X])[:, t]

x_cate_train = (ps_predict(train,1)mx0.predict(train[X]) + ps_predict(train,0)mx1.predict(train[X]))

x_cate_test = test.assign(cate=(ps_predict(test,1)mx0.predict(test[X]) + ps_predict(test,0)mx1.predict(test[X])))

matheusfacure commented 1 year ago

Solved in another issue