-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathprecommit.log.txt
More file actions
500 lines (441 loc) · 26.1 KB
/
precommit.log.txt
File metadata and controls
500 lines (441 loc) · 26.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
Check JSON syntax........................................................[42mPassed[m
check for merge conflicts................................................[42mPassed[m
check that scripts with shebangs are executable..........................[42mPassed[m
check for broken symlinks............................(no files to check)[46;30mSkipped[m
Check TOML syntax....................................(no files to check)[46;30mSkipped[m
check that executables have shebangs.................(no files to check)[46;30mSkipped[m
check for added large files..............................................[42mPassed[m
check python ast.........................................................[42mPassed[m
check yaml...........................................(no files to check)[46;30mSkipped[m
fix end of files.........................................................[41mFailed[m
[2m- hook id: end-of-file-fixer[m
[2m- exit code: 1[m
[2m- files were modified by this hook[m
Fixing msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb
mixed line ending........................................................[42mPassed[m
trim trailing whitespace.................................................[41mFailed[m
[2m- hook id: trailing-whitespace[m
[2m- exit code: 1[m
[2m- files were modified by this hook[m
Fixing msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py
python tests naming..................................(no files to check)[46;30mSkipped[m
mixed line ending........................................................[42mPassed[m
ssort....................................................................[41mFailed[m
[2m- hook id: ssort[m
[2m- exit code: 1[m
[2m- files were modified by this hook[m
ERROR: unresolved dependency 'display' in msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py: line 229, column 0
3 files were left unchanged, 1 file was not sortable
Sorting msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py
1 file was resorted
ruff check...............................................................[41mFailed[m
[2m- hook id: ruff-check[m
[2m- exit code: 1[m
[2m- files were modified by this hook[m
[1mmsml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py[0m[36m:[0m36[36m:[0m1[36m:[0m [1m[31mE402[0m Module level import not at top of file
[1mmsml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py[0m[36m:[0m37[36m:[0m1[36m:[0m [1m[31mE402[0m Module level import not at top of file
[1mmsml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py[0m[36m:[0m38[36m:[0m1[36m:[0m [1m[31mE402[0m Module level import not at top of file
[1mmsml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py[0m[36m:[0m40[36m:[0m1[36m:[0m [1m[31mE402[0m Module level import not at top of file
[1mmsml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py[0m[36m:[0m41[36m:[0m1[36m:[0m [1m[31mE402[0m Module level import not at top of file
[1mmsml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py[0m[36m:[0m229[36m:[0m1[36m:[0m [1m[31mF821[0m Undefined name `display`
[1mmsml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py[0m[36m:[0m358[36m:[0m1[36m:[0m [1m[31mE402[0m Module level import not at top of file
[1mmsml610/tutorials/L08_causal_inference/L08_04_02_causal_inference.py[0m[36m:[0m46[36m:[0m1[36m:[0m [1m[31mE402[0m Module level import not at top of file
[1mmsml610/tutorials/L08_causal_inference/L08_04_02_causal_inference.py[0m[36m:[0m47[36m:[0m1[36m:[0m [1m[31mE402[0m Module level import not at top of file
[1mmsml610/tutorials/L08_causal_inference/L08_04_02_causal_inference.py[0m[36m:[0m56[36m:[0m1[36m:[0m [1m[31mE402[0m Module level import not at top of file
[1mmsml610/tutorials/L08_causal_inference/L08_04_02_causal_inference.py[0m[36m:[0m58[36m:[0m1[36m:[0m [1m[31mE402[0m Module level import not at top of file
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m1[36m:[0m7[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m1[36m:[0m14[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m1[36m:[0m23[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m1[36m:[0m44[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m1[36m:[0m52[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m1[36m:[0m57[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m1[36m:[0m61[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m1[36m:[0m65[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m1[36m:[0m69[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m1[36m:[0m73[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m1[36m:[0m81[36m:[0m [1m[31minvalid-syntax[0m: Expected an identifier
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m2[36m:[0m16[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m2[36m:[0m27[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m2[36m:[0m30[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m2[36m:[0m39[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m2[36m:[0m51[36m:[0m [1m[31minvalid-syntax[0m: Expected `,`, found name
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m2[36m:[0m57[36m:[0m [1m[31minvalid-syntax[0m: Expected `,`, found name
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m2[36m:[0m62[36m:[0m [1m[31minvalid-syntax[0m: Expected `,`, found name
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m2[36m:[0m71[36m:[0m [1m[31minvalid-syntax[0m: Expected `,`, found name
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m3[36m:[0m1[36m:[0m [1m[31minvalid-syntax[0m: Unexpected indentation
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m3[36m:[0m13[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m3[36m:[0m18[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m3[36m:[0m26[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m3[36m:[0m31[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m3[36m:[0m39[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m3[36m:[0m43[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m3[36m:[0m48[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m3[36m:[0m55[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m3[36m:[0m58[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m3[36m:[0m63[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m4[36m:[0m11[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 18[36m:[0m4[36m:[0m20[36m:[0m [1m[31minvalid-syntax[0m: Simple statements must be separated by newlines or semicolons
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0mcell 20[36m:[0m1[36m:[0m1[36m:[0m [1m[31minvalid-syntax[0m: Expected a statement
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py[0m[36m:[0m60[36m:[0m1[36m:[0m [1m[31mE402[0m Module level import not at top of file
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py[0m[36m:[0m63[36m:[0m1[36m:[0m [1m[31mE402[0m Module level import not at top of file
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py[0m[36m:[0m84[36m:[0m1[36m:[0m [1m[31mE402[0m Module level import not at top of file
[1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py[0m[36m:[0m92[36m:[0m1[36m:[0m [1m[31mE402[0m Module level import not at top of file
Found 55 errors (7 fixed, 48 remaining).
ruff format..............................................................[41mFailed[m
[2m- hook id: ruff-format[m
[2m- exit code: 2[m
[2m- files were modified by this hook[m
[1;31merror[0m[1m:[0m [1mFailed to parse[0m [1mmsml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb[0m[36m:[0m18[36m:[0m1[36m:[0m7[36m:[0m Simple statements must be separated by newlines or semicolons
5 files reformatted, 2 files left unchanged
jupytext.................................................................[41mFailed[m
[2m- hook id: jupytext[m
[2m- exit code: 6[m
[2m- files were modified by this hook[m
[jupytext] Reading class_scripts/common_utils.py in format py
[jupytext] Warning: class_scripts/common_utils.py is not a paired notebook
[jupytext] Reading msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.ipynb in format ipynb
[jupytext] Error: msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.ipynb and msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py are inconsistent.
--- msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py
+++ msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.ipynb
@@ -6,7 +6,7 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
-# jupytext_version: 1.19.1
+# jupytext_version: 1.19.0
# kernelspec:
# display_name: Python 3 (ipykernel)
# language: python
@@ -366,7 +366,7 @@
label="True Mean",
color="0.3",
)
-plt.legend()
+plt.legend();
# %% [markdown]
# - With the SEM you can create an interval that contains the true mean 95% of the experiments
@@ -436,7 +436,7 @@
)
plt.xlabel("Conversion")
-plt.legend()
+plt.legend();
# %% [markdown]
# ## Cell 2.4: Hypothesis Testing.
Please revert JUST ONE of the files with EITHER
git reset msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.ipynb && git checkout -- msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.ipynb
OR
git reset msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py && git checkout -- msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py
[jupytext] Reading msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py in format py
[jupytext] Error: msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.ipynb and msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py are inconsistent.
--- msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py
+++ msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.ipynb
@@ -6,7 +6,7 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
-# jupytext_version: 1.19.1
+# jupytext_version: 1.19.0
# kernelspec:
# display_name: Python 3 (ipykernel)
# language: python
@@ -366,7 +366,7 @@
label="True Mean",
color="0.3",
)
-plt.legend()
+plt.legend();
# %% [markdown]
# - With the SEM you can create an interval that contains the true mean 95% of the experiments
@@ -436,7 +436,7 @@
)
plt.xlabel("Conversion")
-plt.legend()
+plt.legend();
# %% [markdown]
# ## Cell 2.4: Hypothesis Testing.
Please revert JUST ONE of the files with EITHER
git reset msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.ipynb && git checkout -- msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.ipynb
OR
git reset msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py && git checkout -- msml610/tutorials/L08_causal_inference/L08_04_01_causal_inference.py
[jupytext] Reading msml610/tutorials/L08_causal_inference/L08_04_02_causal_inference.ipynb in format ipynb
[jupytext] Loading msml610/tutorials/L08_causal_inference/L08_04_02_causal_inference.py
[jupytext] Unchanged msml610/tutorials/L08_causal_inference/L08_04_02_causal_inference.ipynb
[jupytext] Updating msml610/tutorials/L08_causal_inference/L08_04_02_causal_inference.py
[jupytext] Error: the git index is outdated.
Please add the paired notebook with:
git add msml610/tutorials/L08_causal_inference/L08_04_02_causal_inference.py
[jupytext] Reading msml610/tutorials/L08_causal_inference/L08_04_02_causal_inference.py in format py
[jupytext] Loading msml610/tutorials/L08_causal_inference/L08_04_02_causal_inference.ipynb
[jupytext] Unchanged msml610/tutorials/L08_causal_inference/L08_04_02_causal_inference.ipynb
[jupytext] Unchanged msml610/tutorials/L08_causal_inference/L08_04_02_causal_inference.py
[jupytext] Error: the git index is outdated.
Please add the paired notebook with:
git add msml610/tutorials/L08_causal_inference/L08_04_02_causal_inference.py
[jupytext] Reading msml610/tutorials/L08_causal_inference/L08_04_05_causal_inference_utils.py in format py
[jupytext] Warning: msml610/tutorials/L08_causal_inference/L08_04_05_causal_inference_utils.py is not a paired notebook
[jupytext] Reading msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb in format ipynb
[jupytext] Error: msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb and msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py are inconsistent.
--- msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py
+++ msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb
@@ -6,7 +6,7 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
-# jupytext_version: 1.19.1
+# jupytext_version: 1.19.0
# kernelspec:
# display_name: Python 3 (ipykernel)
# language: python
@@ -23,6 +23,8 @@
import logging
import os
+import matplotlib.pyplot as plt
+import seaborn as sns
# %%
# import helpers.hmodule as hmodule
@@ -58,6 +60,7 @@
# %%
import pandas as pd
+import numpy as np
df = pd.read_csv(os.path.join(dir_name, "management_training.csv"))
import helpers.hpandas_display as hpanddis
@@ -86,21 +89,19 @@
show_distributions = True
show_correlations = True
-hpanstat.explore_dataframe(
- df,
- show_distributions=show_distributions,
- show_correlations=show_correlations,
-)
+hpanstat.explore_dataframe(df, show_distributions=show_distributions, show_correlations=show_correlations)
+
+# %%
+model = smf.ols("engagement_score ~ intervention",
+ data=df).fit()
+print("ATE:", model.params["intervention"])
+print("95% CI:", model.conf_int().loc["intervention", :].values.T)
# %%
import statsmodels.formula.api as smf
-# %%
-model = smf.ols("engagement_score ~ intervention", data=df).fit()
-print("ATE:", model.params["intervention"])
-print("95% CI:", model.conf_int().loc["intervention", :].values.T)
-
-smf.ols("engagement_score ~ intervention", data=df).fit().summary().tables[1]
+smf.ols("engagement_score ~ intervention",
+ data=df).fit().summary().tables[1]
# %%
mtl0cire05.plot_engagement_vs_intervention(df)
@@ -114,46 +115,41 @@
mtl0cire05.plot_engagement_vs_intervention_by_department(df)
# %%
-# mtl0cire05.plot_all_variables_vs_intervention(df)
+#mtl0cire05.plot_all_variables_vs_intervention(df)
# %%
mtl0cire05.plot_all_variables_density_by_intervention(df)
# %%
# To reduce this bias, you can adjust for the covariates you have in your data.
-model = smf.ols(
- """
+model = smf.ols("""
engagement_score ~ intervention
+ tenure + last_engagement_score + department_score
- + n_of_reports + C(gender) + C(role)""",
- data=df,
-).fit()
+ + n_of_reports + C(gender) + C(role)""", data=df).fit()
print("ATE:", model.params["intervention"])
print("95% CI:", model.conf_int().loc["intervention", :].values.T)
# %%
-model = smf.ols("engagement_score ~ intervention", data=df).fit()
+model = smf.ols("engagement_score ~ intervention",
+ data=df).fit()
print("ATE:", model.params["intervention"])
print("95% CI:", model.conf_int().loc["intervention", :].values.T)
-# %% [markdown]
-# - The effect estimate here is considerably smaller than the one you got earlier.
-# - This is some indication of positive bias, which means that managers whose
-# employees were already more engaged are more likely to have participated in the
-# manager training program
-
-# %% [markdown]
-# ## Propensity score
+# %%
+- The effect estimate here is considerably smaller than the one you got earlier.
+- This is some indication of positive bias, which means that managers whose
+ employees were already more engaged are more likely to have participated in the
+ manager training program
# %%
-ps_model = smf.logit(
- """
-intervention ~
+## Propensity score
+
+# %%
+ps_model = smf.logit("""
+intervention ~
tenure + last_engagement_score + department_score
- + C(n_of_reports) + C(gender) + C(role)""",
- data=df,
-).fit(disp=0)
+ + C(n_of_reports) + C(gender) + C(role)""", data=df).fit(disp=0)
data_ps = df.copy()
data_ps["propensity_score"] = ps_model.predict(df)
@@ -162,18 +158,16 @@
# %%
# Estimate using propensity score as confounder / covariate.
-model = smf.ols(
- """
+model = smf.ols("""
engagement_score ~ intervention + propensity_score
- """,
- data=data_ps,
-).fit()
+ """, data=data_ps).fit()
print(model.params["intervention"])
-# %% [markdown]
-# ## Propensity score matching
+# %%
+## Propensity score matching
# %%
+from sklearn.neighbors import KNeighborsRegressor
# Perform 1-nearest neighbor propensity score matching.
predicted = mtl0cire05.propensity_score_matching(data_ps)
predicted.head()
Please revert JUST ONE of the files with EITHER
git reset msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb && git checkout -- msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb
OR
git reset msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py && git checkout -- msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py
[jupytext] Reading msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py in format py
[jupytext] Error: msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb and msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py are inconsistent.
--- msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py
+++ msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb
@@ -6,7 +6,7 @@
# extension: .py
# format_name: percent
# format_version: '1.3'
-# jupytext_version: 1.19.1
+# jupytext_version: 1.19.0
# kernelspec:
# display_name: Python 3 (ipykernel)
# language: python
@@ -23,6 +23,8 @@
import logging
import os
+import matplotlib.pyplot as plt
+import seaborn as sns
# %%
# import helpers.hmodule as hmodule
@@ -58,6 +60,7 @@
# %%
import pandas as pd
+import numpy as np
df = pd.read_csv(os.path.join(dir_name, "management_training.csv"))
import helpers.hpandas_display as hpanddis
@@ -86,21 +89,19 @@
show_distributions = True
show_correlations = True
-hpanstat.explore_dataframe(
- df,
- show_distributions=show_distributions,
- show_correlations=show_correlations,
-)
+hpanstat.explore_dataframe(df, show_distributions=show_distributions, show_correlations=show_correlations)
+
+# %%
+model = smf.ols("engagement_score ~ intervention",
+ data=df).fit()
+print("ATE:", model.params["intervention"])
+print("95% CI:", model.conf_int().loc["intervention", :].values.T)
# %%
import statsmodels.formula.api as smf
-# %%
-model = smf.ols("engagement_score ~ intervention", data=df).fit()
-print("ATE:", model.params["intervention"])
-print("95% CI:", model.conf_int().loc["intervention", :].values.T)
-
-smf.ols("engagement_score ~ intervention", data=df).fit().summary().tables[1]
+smf.ols("engagement_score ~ intervention",
+ data=df).fit().summary().tables[1]
# %%
mtl0cire05.plot_engagement_vs_intervention(df)
@@ -114,46 +115,41 @@
mtl0cire05.plot_engagement_vs_intervention_by_department(df)
# %%
-# mtl0cire05.plot_all_variables_vs_intervention(df)
+#mtl0cire05.plot_all_variables_vs_intervention(df)
# %%
mtl0cire05.plot_all_variables_density_by_intervention(df)
# %%
# To reduce this bias, you can adjust for the covariates you have in your data.
-model = smf.ols(
- """
+model = smf.ols("""
engagement_score ~ intervention
+ tenure + last_engagement_score + department_score
- + n_of_reports + C(gender) + C(role)""",
- data=df,
-).fit()
+ + n_of_reports + C(gender) + C(role)""", data=df).fit()
print("ATE:", model.params["intervention"])
print("95% CI:", model.conf_int().loc["intervention", :].values.T)
# %%
-model = smf.ols("engagement_score ~ intervention", data=df).fit()
+model = smf.ols("engagement_score ~ intervention",
+ data=df).fit()
print("ATE:", model.params["intervention"])
print("95% CI:", model.conf_int().loc["intervention", :].values.T)
-# %% [markdown]
-# - The effect estimate here is considerably smaller than the one you got earlier.
-# - This is some indication of positive bias, which means that managers whose
-# employees were already more engaged are more likely to have participated in the
-# manager training program
-
-# %% [markdown]
-# ## Propensity score
+# %%
+- The effect estimate here is considerably smaller than the one you got earlier.
+- This is some indication of positive bias, which means that managers whose
+ employees were already more engaged are more likely to have participated in the
+ manager training program
# %%
-ps_model = smf.logit(
- """
-intervention ~
+## Propensity score
+
+# %%
+ps_model = smf.logit("""
+intervention ~
tenure + last_engagement_score + department_score
- + C(n_of_reports) + C(gender) + C(role)""",
- data=df,
-).fit(disp=0)
+ + C(n_of_reports) + C(gender) + C(role)""", data=df).fit(disp=0)
data_ps = df.copy()
data_ps["propensity_score"] = ps_model.predict(df)
@@ -162,18 +158,16 @@
# %%
# Estimate using propensity score as confounder / covariate.
-model = smf.ols(
- """
+model = smf.ols("""
engagement_score ~ intervention + propensity_score
- """,
- data=data_ps,
-).fit()
+ """, data=data_ps).fit()
print(model.params["intervention"])
-# %% [markdown]
-# ## Propensity score matching
+# %%
+## Propensity score matching
# %%
+from sklearn.neighbors import KNeighborsRegressor
# Perform 1-nearest neighbor propensity score matching.
predicted = mtl0cire05.propensity_score_matching(data_ps)
predicted.head()
Please revert JUST ONE of the files with EITHER
git reset msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb && git checkout -- msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.ipynb
OR
git reset msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py && git checkout -- msml610/tutorials/L08_causal_inference/L08_04_05_propensity_score.py