forked from uber/causalml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_datasets.py
91 lines (75 loc) · 2.32 KB
/
test_datasets.py
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
import pytest
from causalml.dataset import (
simulate_nuisance_and_easy_treatment,
simulate_hidden_confounder,
simulate_randomized_trial,
)
from causalml.dataset import (
get_synthetic_preds,
get_synthetic_summary,
get_synthetic_auuc,
)
from causalml.dataset import get_synthetic_preds_holdout, get_synthetic_summary_holdout
from causalml.inference.meta import LRSRegressor, XGBTRegressor
@pytest.mark.parametrize(
"synthetic_data_func",
[
simulate_nuisance_and_easy_treatment,
simulate_hidden_confounder,
simulate_randomized_trial,
],
)
def test_get_synthetic_preds(synthetic_data_func):
preds_dict = get_synthetic_preds(
synthetic_data_func=synthetic_data_func,
n=1000,
estimators={
"S Learner (LR)": LRSRegressor(),
"T Learner (XGB)": XGBTRegressor(),
},
)
assert (
preds_dict["S Learner (LR)"].shape[0] == preds_dict["T Learner (XGB)"].shape[0]
)
def test_get_synthetic_summary():
summary = get_synthetic_summary(
synthetic_data_func=simulate_nuisance_and_easy_treatment,
estimators={
"S Learner (LR)": LRSRegressor(),
"T Learner (XGB)": XGBTRegressor(),
},
)
print(summary)
def test_get_synthetic_preds_holdout():
preds_train, preds_valid = get_synthetic_preds_holdout(
synthetic_data_func=simulate_nuisance_and_easy_treatment,
n=1000,
estimators={
"S Learner (LR)": LRSRegressor(),
"T Learner (XGB)": XGBTRegressor(),
},
)
assert (
preds_train["S Learner (LR)"].shape[0]
== preds_train["T Learner (XGB)"].shape[0]
)
assert (
preds_valid["S Learner (LR)"].shape[0]
== preds_valid["T Learner (XGB)"].shape[0]
)
def test_get_synthetic_summary_holdout():
summary = get_synthetic_summary_holdout(
synthetic_data_func=simulate_nuisance_and_easy_treatment
)
print(summary)
def test_get_synthetic_auuc():
preds_dict = get_synthetic_preds(
synthetic_data_func=simulate_nuisance_and_easy_treatment,
n=1000,
estimators={
"S Learner (LR)": LRSRegressor(),
"T Learner (XGB)": XGBTRegressor(),
},
)
auuc_df = get_synthetic_auuc(preds_dict, plot=False)
print(auuc_df)