Ai
1 Star 0 Fork 1

Owen/Python-causalml

forked from 连享会/Python-causalml 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_datasets.py 2.38 KB
一键复制 编辑 原始数据 按行查看 历史
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)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/owen560/Python-causalml.git
git@gitee.com:owen560/Python-causalml.git
owen560
Python-causalml
Python-causalml
v0.12.0

搜索帮助