|
2 | 2 | [](https://codeclimate.com/github/IBM/causallib/test_coverage)
|
3 | 3 | [](https://badge.fury.io/py/causallib)
|
4 | 4 | [](https://causallib.readthedocs.io/en/latest/)
|
5 |
| -# IBM Causal Inference Library |
6 |
| -A Python package for computational inference of causal effect. |
| 5 | +# Causal Inference 360 |
| 6 | +A Python package for inferring causal effects from observational data. |
7 | 7 |
|
8 | 8 | ## Description
|
9 |
| -Causal inference analysis allows estimating of the effect of intervention |
10 |
| -on some outcome from observational data. |
11 |
| -It deals with the selection bias that is inherent to such data. |
| 9 | +Causal inference analysis enables estimating the causal effect of |
| 10 | +an intervention on some outcome from real-world non-experimental observational data. |
12 | 11 |
|
13 |
| -This python package allows creating modular causal inference models |
14 |
| -that internally utilize machine learning models of choice, |
15 |
| -and can estimate either individual or average outcome given an intervention. |
16 |
| -The package also provides the means to evaluate the performance of the |
17 |
| -machine learning models and their predictions. |
| 12 | +This package provides a suite of causal methods, |
| 13 | +under a unified scikit-learn-inspired API. |
| 14 | +It implements meta-algorithms that allow plugging in arbitrarily complex machine learning models. |
| 15 | +This modular approach supports highly-flexible causal modelling. |
| 16 | +The fit-and-predict-like API makes it possible to train on one set of examples |
| 17 | +and estimate an effect on the other (out-of-bag), |
| 18 | +which allows for a more "honest"<sup>1</sup> effect estimation. |
| 19 | + |
| 20 | +The package also includes an evaluation suite. |
| 21 | +Since most causal-models utilize machine learning models internally, |
| 22 | +we can diagnose poor-performing models by re-interpreting known ML evaluations from a causal perspective. |
| 23 | +See [arXiv:1906.00442](https://arxiv.org/abs/1906.00442) for more details on how. |
| 24 | + |
| 25 | + |
| 26 | +------------- |
| 27 | +<sup>1</sup> Borrowing [Wager & Athey](https://arxiv.org/abs/1510.04342) terminology of avoiding overfit. |
18 | 28 |
|
19 |
| -The machine learning models must comply with scikit-learn's api |
20 |
| -and contain `fit()` and `predict()` functions. |
21 |
| -Categorical models must also implement `predict_proba()`. |
22 | 29 |
|
23 | 30 | ## Installation
|
24 | 31 | ```bash
|
25 | 32 | pip install causallib
|
26 | 33 | ```
|
27 | 34 |
|
28 | 35 | ## Usage
|
29 |
| -In general, the package is imported using the name `causallib`. |
30 |
| -For example, use |
| 36 | +In general, the package is imported using the name `causallib`. |
| 37 | +Every causal model requires an internal machine-learning model. |
| 38 | +`causallib` supports any model that has a sklearn-like fit-predict API |
| 39 | +(note some models might require a `predict_proba` implementation). |
| 40 | + |
| 41 | +For example: |
31 | 42 | ```Python
|
32 | 43 | from sklearn.linear_model import LogisticRegression
|
33 | 44 | from causallib.estimation import IPW
|
| 45 | +from causallib.datasets import load_nhefs |
| 46 | + |
| 47 | +data = load_nhefs() |
34 | 48 | ipw = IPW(LogisticRegression())
|
| 49 | +ipw.fit(data.X, data.a) |
| 50 | +potential_outcomes = ipw.estimate_population_outcome(data.X, data.a, data.y) |
| 51 | +effect = ipw.estimate_effect(potential_outcomes[1], potential_outcomes[0]) |
35 | 52 | ```
|
36 | 53 | Comprehensive Jupyter Notebooks examples can be found in the [examples directory](examples).
|
37 | 54 |
|
| 55 | +### Approach to causal-inference |
| 56 | +Some key points on how we address causal-inference estimation |
| 57 | + |
| 58 | +##### 1. Emphasis on potential outcome prediction |
| 59 | +Causal effect may be the desired outcome. |
| 60 | +However, every effect is defined by two potential (counterfactual) outcomes. |
| 61 | +We adopt this two-step approach by separating the effect-estimating step |
| 62 | +from the potential-outcome-prediction step. |
| 63 | +A beneficial consequence to this approach is that it better supports |
| 64 | +multi-treatment problems where "effect" is not well-defined. |
| 65 | + |
| 66 | +##### 2. Stratified average treatment effect |
| 67 | +The causal inference literature devotes special attention to the population |
| 68 | +on which the effect is estimated on. |
| 69 | +For example, ATE (average treatment effect on the entire sample), |
| 70 | +ATT (average treatment effect on the treated), etc. |
| 71 | +By allowing out-of-bag estimation, we leave this specification to the user. |
| 72 | +For example, ATE is achieved by `model.estimate_population_outcome(X, a)` |
| 73 | +and ATT is done by stratifying on the treated: `model.estimate_population_outcome(X.loc[a==1], a.loc[a==1])` |
| 74 | + |
| 75 | +##### 3. Families of causal inference models |
| 76 | +We distinguish between two types of models: |
| 77 | +* *Weight models*: weight the data to balance between the treatment and control groups, |
| 78 | + and then estimates the potential outcome by using a weighted average of the observed outcome. |
| 79 | + Inverse Probability of Treatment Weighting (IPW or IPTW) is the most known example of such models. |
| 80 | +* *Direct outcome models*: uses the covariates (features) and treatment assignment to build a |
| 81 | + model that predicts the outcome directly. The model can then be used to predict the outcome |
| 82 | + under any assignment of treatment values, specifically the potential-outcome under assignment of |
| 83 | + all controls or all treated. |
| 84 | + These models are usually known as *Standardization* models, and it should be noted that, currently, |
| 85 | + they are the only ones able to generate *individual effect estimation* (otherwise known as CATE). |
| 86 | + |
| 87 | +##### 4. Confounders and DAGs |
| 88 | +One of the most important steps in causal inference analysis is to have |
| 89 | +proper selection on both dimensions of the data to avoid introducing bias: |
| 90 | +* On rows: thoughtfully choosing the right inclusion\exclusion criteria |
| 91 | + for individuals in the data. |
| 92 | +* On columns: thoughtfully choosing what covariates (features) act as confounders |
| 93 | + and should be included in the analysis. |
| 94 | + |
| 95 | +This is a place where domain expert knowledge is required and cannot be fully and truly automated |
| 96 | +by algorithms. |
| 97 | +This package assumes that the data provided to the model fit the criteria. |
| 98 | +However, filtering can be applied in real-time using a scikit-learn pipeline estimator |
| 99 | +that chains preprocessing steps (that can filter rows and select columns) with a causal model at the end. |
| 100 | + |
0 commit comments