doubleml-pipeline 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- doubleml_pipeline-0.1.0/LICENSE +202 -0
- doubleml_pipeline-0.1.0/PKG-INFO +240 -0
- doubleml_pipeline-0.1.0/README.md +216 -0
- doubleml_pipeline-0.1.0/pyproject.toml +25 -0
- doubleml_pipeline-0.1.0/setup.cfg +4 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/__init__.py +15 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/evaluation/__init__.py +15 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/evaluation/metrics.py +156 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/evaluation/runner.py +350 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/evaluation/selection.py +58 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/evaluation/sensitivity.py +73 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/models/__init__.py +15 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/models/flaml_dml.py +88 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/optimization.py +262 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/preprocessing/__init__.py +15 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/preprocessing/features.py +139 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/preprocessing/scalers.py +211 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/utils/__init__.py +15 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/utils/io.py +102 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/visualization/__init__.py +15 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/visualization/plots.py +1716 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline/workflow.py +1681 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline.egg-info/PKG-INFO +240 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline.egg-info/SOURCES.txt +36 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline.egg-info/dependency_links.txt +1 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline.egg-info/requires.txt +16 -0
- doubleml_pipeline-0.1.0/src/doubleml_pipeline.egg-info/top_level.txt +1 -0
- doubleml_pipeline-0.1.0/test/test_features.py +59 -0
- doubleml_pipeline-0.1.0/test/test_flaml_dml.py +40 -0
- doubleml_pipeline-0.1.0/test/test_io.py +48 -0
- doubleml_pipeline-0.1.0/test/test_metrics.py +55 -0
- doubleml_pipeline-0.1.0/test/test_optimization.py +56 -0
- doubleml_pipeline-0.1.0/test/test_plots.py +51 -0
- doubleml_pipeline-0.1.0/test/test_runner.py +44 -0
- doubleml_pipeline-0.1.0/test/test_scalers.py +65 -0
- doubleml_pipeline-0.1.0/test/test_selection.py +46 -0
- doubleml_pipeline-0.1.0/test/test_sensitivity.py +53 -0
- doubleml_pipeline-0.1.0/test/test_workflow.py +193 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: doubleml-pipeline
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A causal inference pipeline utilizing DoubleML and FLAML
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: numpy>=1.20.0
|
|
9
|
+
Requires-Dist: pandas>=1.3.0
|
|
10
|
+
Requires-Dist: scikit-learn>=1.0
|
|
11
|
+
Requires-Dist: doubleml>=0.5.0
|
|
12
|
+
Requires-Dist: FLAML>=1.0.0
|
|
13
|
+
Requires-Dist: scipy
|
|
14
|
+
Requires-Dist: patsy
|
|
15
|
+
Requires-Dist: matplotlib
|
|
16
|
+
Requires-Dist: cloudpickle
|
|
17
|
+
Requires-Dist: joblib
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: pytest; extra == "dev"
|
|
20
|
+
Requires-Dist: mypy; extra == "dev"
|
|
21
|
+
Requires-Dist: black; extra == "dev"
|
|
22
|
+
Requires-Dist: isort; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# DoubleML Pipeline
|
|
26
|
+
|
|
27
|
+
A robust Python library for automated causal inference utilizing Double Machine
|
|
28
|
+
Learning (DoubleML) and FLAML AutoML.
|
|
29
|
+
|
|
30
|
+
**By the Google Decision Science System Team**
|
|
31
|
+
|
|
32
|
+
*Note: `doubleml-pipeline` refers to and builds upon the underlying `DoubleML`
|
|
33
|
+
Python package published by [doubleml.org](http://doubleml.org).*
|
|
34
|
+
|
|
35
|
+
--------------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
> [!IMPORTANT] **Caveat on File Generation:** For verification purposes,
|
|
38
|
+
> currently `doubleml_pipeline` generates CSV files and charts explicitly across
|
|
39
|
+
> the process.
|
|
40
|
+
|
|
41
|
+
## Why DoubleML Pipeline?
|
|
42
|
+
|
|
43
|
+
With **DoubleML Pipeline**, you can estimate the true incremental impact and ROI
|
|
44
|
+
of your marketing interventions including pricing and promotions by controlling
|
|
45
|
+
for complex, high-dimensional confounders.
|
|
46
|
+
|
|
47
|
+
Causal inference is challenging due to confounding bias. Standard regression
|
|
48
|
+
models often fail to isolate true causal relationships. **DoubleML Pipeline**
|
|
49
|
+
solves this by implementing a rigorous Double Machine Learning (DoubleML)
|
|
50
|
+
framework, combining it with automated machine learning (AutoML) to make causal
|
|
51
|
+
estimation both scientifically robust and highly automated.
|
|
52
|
+
|
|
53
|
+
### Key Features:
|
|
54
|
+
|
|
55
|
+
* **Automated Nuisance Modeling**: Automates nuisance parameter estimation
|
|
56
|
+
using FLAML AutoML. It dynamically searches and tunes candidates (like
|
|
57
|
+
LightGBM, XGBoost) under a specified time budget, removing the guesswork of
|
|
58
|
+
model selection.
|
|
59
|
+
* **Safe Business Unit Scaling**: Normalizes and scales geographical and
|
|
60
|
+
population data securely, ensuring that descaled results represent accurate
|
|
61
|
+
real-world business metrics (KPI, ROI) without introducing mathematical
|
|
62
|
+
singularities.
|
|
63
|
+
* **Treatment Effect Heterogeneity (CATE)**: Automatically fits continuous
|
|
64
|
+
splines or binary bases to estimate how treatment effects vary across
|
|
65
|
+
different contexts (Conditional Average Treatment Effects).
|
|
66
|
+
* **Sensitivity Analysis (OVB)**: Runs robust omitted variable bias (OVB)
|
|
67
|
+
checks to evaluate how sensitive your causal estimates are to unobserved
|
|
68
|
+
confounders.
|
|
69
|
+
* **Publication-Ready Visualizations**: Generates comprehensive time series
|
|
70
|
+
line plots, stacked contribution bar charts, cross-sectional ROI
|
|
71
|
+
comparisons, and prior distribution shapes.
|
|
72
|
+
|
|
73
|
+
--------------------------------------------------------------------------------
|
|
74
|
+
|
|
75
|
+
## Getting Started
|
|
76
|
+
|
|
77
|
+
### Prerequisites
|
|
78
|
+
|
|
79
|
+
Before running the pipeline, ensure you have:
|
|
80
|
+
|
|
81
|
+
* **Python 3.9** or later.
|
|
82
|
+
|
|
83
|
+
### Installation
|
|
84
|
+
|
|
85
|
+
You can install the library directly from PyPI:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install doubleml-pipeline
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Alternatively, to install from source:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
git clone https://github.com/google/doubleml-pipeline.git
|
|
95
|
+
cd doubleml-pipeline
|
|
96
|
+
pip install .
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Quick Start Example
|
|
100
|
+
|
|
101
|
+
Here is how to initialize and run the causal pipeline in a standard Python
|
|
102
|
+
environment, explicitly configuring all scaling, modeling, and financial
|
|
103
|
+
parameters:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
import pandas as pd
|
|
107
|
+
from doubleml_pipeline.preprocessing.scalers import CausalDataScaler
|
|
108
|
+
from doubleml_pipeline.workflow import CausalWorkflowOrchestrator
|
|
109
|
+
|
|
110
|
+
# 1. Load your dataset
|
|
111
|
+
df = pd.read_csv("path/to/your/marketing_data.csv")
|
|
112
|
+
|
|
113
|
+
# 2. Initialize the scaler with explicit scaling strategies per column
|
|
114
|
+
scaler = CausalDataScaler(
|
|
115
|
+
standardize_cols=["holiday_index", "seasonality_factor"],
|
|
116
|
+
population_standardize_cols=["competitor_spend"],
|
|
117
|
+
population_median_normalize_cols=["sales_revenue", "tv_spend"],
|
|
118
|
+
min_max_cols=["store_count"],
|
|
119
|
+
median_normalize_cols=["discount_rate"],
|
|
120
|
+
population_col="geo_population",
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
# 3. Initialize the orchestrator with all explicit configuration parameters
|
|
124
|
+
orchestrator = CausalWorkflowOrchestrator(
|
|
125
|
+
# Primary target and treatments
|
|
126
|
+
y_col="sales_revenue",
|
|
127
|
+
d_cols=["discount_rate", "coupon_imps"],
|
|
128
|
+
x_cols_list=[
|
|
129
|
+
["holiday_index", "seasonality_factor", "competitor_spend"],
|
|
130
|
+
["holiday_index", "seasonality_factor", "competitor_spend"],
|
|
131
|
+
],
|
|
132
|
+
# Nuisance estimation models & cross-validation setup
|
|
133
|
+
ml_models_y=["lgbm", "xgboost"],
|
|
134
|
+
ml_models_t=["lgbm", "xgboost"],
|
|
135
|
+
n_folds_list=[5],
|
|
136
|
+
output_dir="./causal_results",
|
|
137
|
+
n_jobs=-1,
|
|
138
|
+
# Conditional Average Treatment Effect (CATE) specification
|
|
139
|
+
covariates_for_cate_list=[
|
|
140
|
+
["seasonality_factor"],
|
|
141
|
+
["seasonality_factor"],
|
|
142
|
+
],
|
|
143
|
+
cate_structure_list=[
|
|
144
|
+
{"type": "auto_additive", "df": 3, "degree": 2, "include_intercept": False},
|
|
145
|
+
{"type": "auto_additive", "df": 3, "degree": 2, "include_intercept": False},
|
|
146
|
+
],
|
|
147
|
+
time_budget=30,
|
|
148
|
+
# Panel data dimensions
|
|
149
|
+
date_col="date",
|
|
150
|
+
geo_col="geo",
|
|
151
|
+
item_col="item",
|
|
152
|
+
geo_name_col="geo_name",
|
|
153
|
+
item_name_col="item_name",
|
|
154
|
+
# Sensitivity analysis (Omitted Variable Bias)
|
|
155
|
+
run_sensitivity=True,
|
|
156
|
+
sensitivity_scope=["total", "geo", "item"],
|
|
157
|
+
# Ground truth validation (set True if ground truth effect columns exist)
|
|
158
|
+
ground_truth_existence=False,
|
|
159
|
+
ground_truth_effect_column=None,
|
|
160
|
+
# Treatment type classification & monetary spend mapping
|
|
161
|
+
treatment_types={
|
|
162
|
+
"discount_rate": "percentage",
|
|
163
|
+
"coupon_imps": "spend",
|
|
164
|
+
},
|
|
165
|
+
treatment_spend_cols={
|
|
166
|
+
"coupon_imps": "coupon_cost",
|
|
167
|
+
},
|
|
168
|
+
sales_col="sales_revenue",
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
# 4. Execute the full 4-phase pipeline (Grid Search -> Shortlist -> Ensemble -> Consolidation)
|
|
172
|
+
orchestrator.run_full_pipeline(
|
|
173
|
+
df=df,
|
|
174
|
+
scaler=scaler,
|
|
175
|
+
top_n=3,
|
|
176
|
+
n_reps=10,
|
|
177
|
+
)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
The orchestrator will execute the models in parallel, select the best
|
|
181
|
+
estimators, run repetitions to calculate robust confidence bounds, perform
|
|
182
|
+
sensitivity checks, and write all dataframes and plot artifacts to the specified
|
|
183
|
+
`./causal_results` directory.
|
|
184
|
+
|
|
185
|
+
### Important Notes on Outputs & Optimization
|
|
186
|
+
|
|
187
|
+
1. **ROI Charts:** ROI charts (`003_promo_roi_by_month` and
|
|
188
|
+
`004_promo_roi_by_entity`) are generated only if `treatment_types` is set to
|
|
189
|
+
`"percentage"` or `"impressions"` (requires `treatment_spend_cols`
|
|
190
|
+
specification). The default value for `treatment_types` is `"spend"`. For
|
|
191
|
+
`"spend"` treatments, ROI charts will not be generated specifically because
|
|
192
|
+
they are redundant with the output generated in Phase 4.
|
|
193
|
+
2. **Optimization:** Currently, optimization calculations can only be performed
|
|
194
|
+
if `optimize = True` and `simple_optimization = True` with a single
|
|
195
|
+
treatment. Optimization is not calculated if `simple_optimization = False`
|
|
196
|
+
because the optimization function is under development and optimization for
|
|
197
|
+
multiple treatments is not supported yet.
|
|
198
|
+
|
|
199
|
+
--------------------------------------------------------------------------------
|
|
200
|
+
|
|
201
|
+
## Engaging with the Project
|
|
202
|
+
|
|
203
|
+
### Documentation & Examples
|
|
204
|
+
|
|
205
|
+
* **API Reference**: For a comprehensive list of modules, classes, and
|
|
206
|
+
function signatures, refer to the [API Reference](docs/api_reference.md).
|
|
207
|
+
* **Interactive Sample**: Check out the
|
|
208
|
+
[Sample Jupyter Notebook](examples/sample_notebook.ipynb) which walks
|
|
209
|
+
through simulating realistic panel marketing data, engineering lagged
|
|
210
|
+
features, scaling, running the DML pipeline, and plotting the results.
|
|
211
|
+
|
|
212
|
+
### Contributing & Feedback
|
|
213
|
+
|
|
214
|
+
We welcome contributions!
|
|
215
|
+
|
|
216
|
+
* **Reporting Issues**: If you encounter bugs or want to request features,
|
|
217
|
+
please open an issue in the GitHub repository issue tracker.
|
|
218
|
+
* **Submitting Changes**: Please see `CONTRIBUTING.md` for our guidelines on
|
|
219
|
+
submitting pull requests.
|
|
220
|
+
|
|
221
|
+
--------------------------------------------------------------------------------
|
|
222
|
+
|
|
223
|
+
## References
|
|
224
|
+
|
|
225
|
+
1. **Debiased Machine Learning method** Victor Chernozhukov, Denis Chetverikov,
|
|
226
|
+
Mert Demirer, Esther Duflo, Christian Hansen, Whitney Newey, James Robins.
|
|
227
|
+
*Double/debiased machine learning for treatment and structural parameters*.
|
|
228
|
+
[arXiv:1608.00060](https://arxiv.org/abs/1608.00060)
|
|
229
|
+
|
|
230
|
+
2. **Hyperparameter Tuning for Causal Inference with Double Machine Learning: A
|
|
231
|
+
Simulation Study** Martin Spindler, et al.
|
|
232
|
+
[arXiv:2212.04351](https://arxiv.org/abs/2212.04351)
|
|
233
|
+
|
|
234
|
+
3. **Debiased Machine Learning of Conditional Average Treatment Effects and
|
|
235
|
+
Other Causal Functions** Vira Semenova, Victor Chernozhukov.
|
|
236
|
+
[arXiv:1702.06240](https://arxiv.org/abs/1702.06240)
|
|
237
|
+
|
|
238
|
+
4. **Multiway Cluster Robust Double/Debiased Machine Learning** Harold D.
|
|
239
|
+
Chiang, Kengo Kato, Yukitoshi Matsushita, Takuya Ishihara.
|
|
240
|
+
[arXiv:1909.05294](https://arxiv.org/abs/1909.05294)
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# DoubleML Pipeline
|
|
2
|
+
|
|
3
|
+
A robust Python library for automated causal inference utilizing Double Machine
|
|
4
|
+
Learning (DoubleML) and FLAML AutoML.
|
|
5
|
+
|
|
6
|
+
**By the Google Decision Science System Team**
|
|
7
|
+
|
|
8
|
+
*Note: `doubleml-pipeline` refers to and builds upon the underlying `DoubleML`
|
|
9
|
+
Python package published by [doubleml.org](http://doubleml.org).*
|
|
10
|
+
|
|
11
|
+
--------------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
> [!IMPORTANT] **Caveat on File Generation:** For verification purposes,
|
|
14
|
+
> currently `doubleml_pipeline` generates CSV files and charts explicitly across
|
|
15
|
+
> the process.
|
|
16
|
+
|
|
17
|
+
## Why DoubleML Pipeline?
|
|
18
|
+
|
|
19
|
+
With **DoubleML Pipeline**, you can estimate the true incremental impact and ROI
|
|
20
|
+
of your marketing interventions including pricing and promotions by controlling
|
|
21
|
+
for complex, high-dimensional confounders.
|
|
22
|
+
|
|
23
|
+
Causal inference is challenging due to confounding bias. Standard regression
|
|
24
|
+
models often fail to isolate true causal relationships. **DoubleML Pipeline**
|
|
25
|
+
solves this by implementing a rigorous Double Machine Learning (DoubleML)
|
|
26
|
+
framework, combining it with automated machine learning (AutoML) to make causal
|
|
27
|
+
estimation both scientifically robust and highly automated.
|
|
28
|
+
|
|
29
|
+
### Key Features:
|
|
30
|
+
|
|
31
|
+
* **Automated Nuisance Modeling**: Automates nuisance parameter estimation
|
|
32
|
+
using FLAML AutoML. It dynamically searches and tunes candidates (like
|
|
33
|
+
LightGBM, XGBoost) under a specified time budget, removing the guesswork of
|
|
34
|
+
model selection.
|
|
35
|
+
* **Safe Business Unit Scaling**: Normalizes and scales geographical and
|
|
36
|
+
population data securely, ensuring that descaled results represent accurate
|
|
37
|
+
real-world business metrics (KPI, ROI) without introducing mathematical
|
|
38
|
+
singularities.
|
|
39
|
+
* **Treatment Effect Heterogeneity (CATE)**: Automatically fits continuous
|
|
40
|
+
splines or binary bases to estimate how treatment effects vary across
|
|
41
|
+
different contexts (Conditional Average Treatment Effects).
|
|
42
|
+
* **Sensitivity Analysis (OVB)**: Runs robust omitted variable bias (OVB)
|
|
43
|
+
checks to evaluate how sensitive your causal estimates are to unobserved
|
|
44
|
+
confounders.
|
|
45
|
+
* **Publication-Ready Visualizations**: Generates comprehensive time series
|
|
46
|
+
line plots, stacked contribution bar charts, cross-sectional ROI
|
|
47
|
+
comparisons, and prior distribution shapes.
|
|
48
|
+
|
|
49
|
+
--------------------------------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
## Getting Started
|
|
52
|
+
|
|
53
|
+
### Prerequisites
|
|
54
|
+
|
|
55
|
+
Before running the pipeline, ensure you have:
|
|
56
|
+
|
|
57
|
+
* **Python 3.9** or later.
|
|
58
|
+
|
|
59
|
+
### Installation
|
|
60
|
+
|
|
61
|
+
You can install the library directly from PyPI:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install doubleml-pipeline
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Alternatively, to install from source:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
git clone https://github.com/google/doubleml-pipeline.git
|
|
71
|
+
cd doubleml-pipeline
|
|
72
|
+
pip install .
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Quick Start Example
|
|
76
|
+
|
|
77
|
+
Here is how to initialize and run the causal pipeline in a standard Python
|
|
78
|
+
environment, explicitly configuring all scaling, modeling, and financial
|
|
79
|
+
parameters:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import pandas as pd
|
|
83
|
+
from doubleml_pipeline.preprocessing.scalers import CausalDataScaler
|
|
84
|
+
from doubleml_pipeline.workflow import CausalWorkflowOrchestrator
|
|
85
|
+
|
|
86
|
+
# 1. Load your dataset
|
|
87
|
+
df = pd.read_csv("path/to/your/marketing_data.csv")
|
|
88
|
+
|
|
89
|
+
# 2. Initialize the scaler with explicit scaling strategies per column
|
|
90
|
+
scaler = CausalDataScaler(
|
|
91
|
+
standardize_cols=["holiday_index", "seasonality_factor"],
|
|
92
|
+
population_standardize_cols=["competitor_spend"],
|
|
93
|
+
population_median_normalize_cols=["sales_revenue", "tv_spend"],
|
|
94
|
+
min_max_cols=["store_count"],
|
|
95
|
+
median_normalize_cols=["discount_rate"],
|
|
96
|
+
population_col="geo_population",
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
# 3. Initialize the orchestrator with all explicit configuration parameters
|
|
100
|
+
orchestrator = CausalWorkflowOrchestrator(
|
|
101
|
+
# Primary target and treatments
|
|
102
|
+
y_col="sales_revenue",
|
|
103
|
+
d_cols=["discount_rate", "coupon_imps"],
|
|
104
|
+
x_cols_list=[
|
|
105
|
+
["holiday_index", "seasonality_factor", "competitor_spend"],
|
|
106
|
+
["holiday_index", "seasonality_factor", "competitor_spend"],
|
|
107
|
+
],
|
|
108
|
+
# Nuisance estimation models & cross-validation setup
|
|
109
|
+
ml_models_y=["lgbm", "xgboost"],
|
|
110
|
+
ml_models_t=["lgbm", "xgboost"],
|
|
111
|
+
n_folds_list=[5],
|
|
112
|
+
output_dir="./causal_results",
|
|
113
|
+
n_jobs=-1,
|
|
114
|
+
# Conditional Average Treatment Effect (CATE) specification
|
|
115
|
+
covariates_for_cate_list=[
|
|
116
|
+
["seasonality_factor"],
|
|
117
|
+
["seasonality_factor"],
|
|
118
|
+
],
|
|
119
|
+
cate_structure_list=[
|
|
120
|
+
{"type": "auto_additive", "df": 3, "degree": 2, "include_intercept": False},
|
|
121
|
+
{"type": "auto_additive", "df": 3, "degree": 2, "include_intercept": False},
|
|
122
|
+
],
|
|
123
|
+
time_budget=30,
|
|
124
|
+
# Panel data dimensions
|
|
125
|
+
date_col="date",
|
|
126
|
+
geo_col="geo",
|
|
127
|
+
item_col="item",
|
|
128
|
+
geo_name_col="geo_name",
|
|
129
|
+
item_name_col="item_name",
|
|
130
|
+
# Sensitivity analysis (Omitted Variable Bias)
|
|
131
|
+
run_sensitivity=True,
|
|
132
|
+
sensitivity_scope=["total", "geo", "item"],
|
|
133
|
+
# Ground truth validation (set True if ground truth effect columns exist)
|
|
134
|
+
ground_truth_existence=False,
|
|
135
|
+
ground_truth_effect_column=None,
|
|
136
|
+
# Treatment type classification & monetary spend mapping
|
|
137
|
+
treatment_types={
|
|
138
|
+
"discount_rate": "percentage",
|
|
139
|
+
"coupon_imps": "spend",
|
|
140
|
+
},
|
|
141
|
+
treatment_spend_cols={
|
|
142
|
+
"coupon_imps": "coupon_cost",
|
|
143
|
+
},
|
|
144
|
+
sales_col="sales_revenue",
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
# 4. Execute the full 4-phase pipeline (Grid Search -> Shortlist -> Ensemble -> Consolidation)
|
|
148
|
+
orchestrator.run_full_pipeline(
|
|
149
|
+
df=df,
|
|
150
|
+
scaler=scaler,
|
|
151
|
+
top_n=3,
|
|
152
|
+
n_reps=10,
|
|
153
|
+
)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The orchestrator will execute the models in parallel, select the best
|
|
157
|
+
estimators, run repetitions to calculate robust confidence bounds, perform
|
|
158
|
+
sensitivity checks, and write all dataframes and plot artifacts to the specified
|
|
159
|
+
`./causal_results` directory.
|
|
160
|
+
|
|
161
|
+
### Important Notes on Outputs & Optimization
|
|
162
|
+
|
|
163
|
+
1. **ROI Charts:** ROI charts (`003_promo_roi_by_month` and
|
|
164
|
+
`004_promo_roi_by_entity`) are generated only if `treatment_types` is set to
|
|
165
|
+
`"percentage"` or `"impressions"` (requires `treatment_spend_cols`
|
|
166
|
+
specification). The default value for `treatment_types` is `"spend"`. For
|
|
167
|
+
`"spend"` treatments, ROI charts will not be generated specifically because
|
|
168
|
+
they are redundant with the output generated in Phase 4.
|
|
169
|
+
2. **Optimization:** Currently, optimization calculations can only be performed
|
|
170
|
+
if `optimize = True` and `simple_optimization = True` with a single
|
|
171
|
+
treatment. Optimization is not calculated if `simple_optimization = False`
|
|
172
|
+
because the optimization function is under development and optimization for
|
|
173
|
+
multiple treatments is not supported yet.
|
|
174
|
+
|
|
175
|
+
--------------------------------------------------------------------------------
|
|
176
|
+
|
|
177
|
+
## Engaging with the Project
|
|
178
|
+
|
|
179
|
+
### Documentation & Examples
|
|
180
|
+
|
|
181
|
+
* **API Reference**: For a comprehensive list of modules, classes, and
|
|
182
|
+
function signatures, refer to the [API Reference](docs/api_reference.md).
|
|
183
|
+
* **Interactive Sample**: Check out the
|
|
184
|
+
[Sample Jupyter Notebook](examples/sample_notebook.ipynb) which walks
|
|
185
|
+
through simulating realistic panel marketing data, engineering lagged
|
|
186
|
+
features, scaling, running the DML pipeline, and plotting the results.
|
|
187
|
+
|
|
188
|
+
### Contributing & Feedback
|
|
189
|
+
|
|
190
|
+
We welcome contributions!
|
|
191
|
+
|
|
192
|
+
* **Reporting Issues**: If you encounter bugs or want to request features,
|
|
193
|
+
please open an issue in the GitHub repository issue tracker.
|
|
194
|
+
* **Submitting Changes**: Please see `CONTRIBUTING.md` for our guidelines on
|
|
195
|
+
submitting pull requests.
|
|
196
|
+
|
|
197
|
+
--------------------------------------------------------------------------------
|
|
198
|
+
|
|
199
|
+
## References
|
|
200
|
+
|
|
201
|
+
1. **Debiased Machine Learning method** Victor Chernozhukov, Denis Chetverikov,
|
|
202
|
+
Mert Demirer, Esther Duflo, Christian Hansen, Whitney Newey, James Robins.
|
|
203
|
+
*Double/debiased machine learning for treatment and structural parameters*.
|
|
204
|
+
[arXiv:1608.00060](https://arxiv.org/abs/1608.00060)
|
|
205
|
+
|
|
206
|
+
2. **Hyperparameter Tuning for Causal Inference with Double Machine Learning: A
|
|
207
|
+
Simulation Study** Martin Spindler, et al.
|
|
208
|
+
[arXiv:2212.04351](https://arxiv.org/abs/2212.04351)
|
|
209
|
+
|
|
210
|
+
3. **Debiased Machine Learning of Conditional Average Treatment Effects and
|
|
211
|
+
Other Causal Functions** Vira Semenova, Victor Chernozhukov.
|
|
212
|
+
[arXiv:1702.06240](https://arxiv.org/abs/1702.06240)
|
|
213
|
+
|
|
214
|
+
4. **Multiway Cluster Robust Double/Debiased Machine Learning** Harold D.
|
|
215
|
+
Chiang, Kengo Kato, Yukitoshi Matsushita, Takuya Ishihara.
|
|
216
|
+
[arXiv:1909.05294](https://arxiv.org/abs/1909.05294)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "doubleml-pipeline"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A causal inference pipeline utilizing DoubleML and FLAML"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"numpy>=1.20.0",
|
|
13
|
+
"pandas>=1.3.0",
|
|
14
|
+
"scikit-learn>=1.0",
|
|
15
|
+
"doubleml>=0.5.0",
|
|
16
|
+
"FLAML>=1.0.0",
|
|
17
|
+
"scipy",
|
|
18
|
+
"patsy",
|
|
19
|
+
"matplotlib",
|
|
20
|
+
"cloudpickle",
|
|
21
|
+
"joblib"
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.optional-dependencies]
|
|
25
|
+
dev = ["pytest", "mypy", "black", "isort"]
|