Added tests for notebooks and fixed confidence interval bug for econml (#204)

* fixed econml bug for CI intervals, 

* removed input prompt from notebooks to enable automatic testing

* added tests for notebooks

* added nbformat, jupyter as req for github actions

* adding jupyter as dependency for workflow runs

* modified readme to be compliant with twine requirements
This commit is contained in:
Amit Sharma 2020-12-06 19:03:30 +05:30 коммит произвёл GitHub
Родитель 04a640628e
Коммит b3234704e8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
26 изменённых файлов: 34687 добавлений и 3706 удалений

2
.github/workflows/python-package.yml поставляемый
Просмотреть файл

@ -28,7 +28,7 @@ jobs:
python -m pip install --upgrade pip
pip install flake8 pytest twine
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install econml causalml
pip install econml causalml nbformat jupyter
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names

Просмотреть файл

@ -482,7 +482,7 @@ Bibtex::
Roadmap
=======
The `projects <https://github.com/microsoft/dowhy/projects>`_ page lists the next steps for DoWhy. If you would like to contribute, have a look at the current projects. If you have a specific request for DoWhy, please raise an issue `here <https://github.com/microsoft/dowhy/issues>`_.
The `projects <https://github.com/microsoft/dowhy/projects>`_ page lists the next steps for DoWhy. If you would like to contribute, have a look at the current projects. If you have a specific request for DoWhy, please `raise an issue <https://github.com/microsoft/dowhy/issues>`_.
Contributing
============

Просмотреть файл

@ -104,12 +104,12 @@
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAANMAAAASCAYAAADBs+vIAAAABHNCSVQICAgIfAhkiAAABjtJREFUaIHtmnmIV1UUxz/mqNNi2qINkWUNLVOZVuRSaD8VhxYMs5XIbBkjsrJNssWYgkBMRLOokawowT/6Q0yyzMxyacNQ2jQt/Y2Kik2maepk0/THOY/f8/3ue+/etxDB7wuP++Oe713OOe/ed+65P6igggpywY3ALGAF8AfQDsxN2edwYD6wE2gFtgOLgWt8nJOABuX9DBwE9gIrgXuAo0L6LuocTc9OA//OCL73tKXge0h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P8Dru0Pu59nR7AAAAAASUVORK5CYII=\n",
"text/latex": [
"$\\displaystyle 1.625771192059154$"
"$\\displaystyle 1.6199979987251836$"
],
"text/plain": [
"1.625771192059154"
"1.6199979987251836"
]
},
"execution_count": 4,
@ -172,27 +172,15 @@
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:dowhy.causal_identifier:Common causes of treatment and outcome:['Z', 'U']\n",
"WARNING:dowhy.causal_identifier:If this is observed data (not from a randomized experiment), there might always be missing confounders. Causal effect cannot be identified perfectly.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"WARN: Do you want to continue by ignoring any unobserved confounders? (use proceed_when_unidentifiable=True to disable this prompt) [y/n] y\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:dowhy.causal_identifier:Instrumental variables for treatment and outcome:[]\n"
"WARNING:dowhy.causal_identifier:If this is observed data (not from a randomized experiment), there might always be missing confounders. Causal effect cannot be identified perfectly.\n",
"INFO:dowhy.causal_identifier:Continuing by ignoring these unobserved confounders because proceed_when_unidentifiable flag is True.\n",
"INFO:dowhy.causal_identifier:Instrumental variables for treatment and outcome:[]\n",
"INFO:dowhy.causal_identifier:Frontdoor variables for treatment and outcome:[]\n"
]
}
],
"source": [
"identification = model.identify_effect()"
"identification = model.identify_effect(proceed_when_unidentifiable=True)"
]
},
{
@ -211,7 +199,6 @@
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:dowhy.causal_identifier:Common causes of treatment and outcome:['Z', 'U']\n",
"WARNING:dowhy.causal_identifier:If this is observed data (not from a randomized experiment), there might always be missing confounders. Causal effect cannot be identified perfectly.\n"
]
},
@ -227,6 +214,7 @@
"output_type": "stream",
"text": [
"INFO:dowhy.causal_identifier:Instrumental variables for treatment and outcome:[]\n",
"INFO:dowhy.causal_identifier:Frontdoor variables for treatment and outcome:[]\n",
"INFO:dowhy.do_sampler:Using WeightingSampler for do sampling.\n",
"INFO:dowhy.do_sampler:Caution: do samplers assume iid data.\n"
]
@ -238,7 +226,8 @@
"sampler = WeightingSampler(df,\n",
" causal_model=model,\n",
" keep_original_treatment=True,\n",
" variable_types={'D': 'b', 'Z': 'c', 'Y': 'c'})\n",
" variable_types={'D': 'b', 'Z': 'c', 'Y': 'c'}\n",
" )\n",
"\n"
]
},
@ -267,12 +256,12 @@
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAOAAAAASCAYAAABCd9LzAAAABHNCSVQICAgIfAhkiAAAB6NJREFUaIHt2m2wVlUVB/AfCokoWRnBVE4SQt7EAalAJ82LJTNJOGSvU5k1ZdmrNakUTcOdZprEHKayssxeJnP6UPmSmimZhZJWVkyhQlhckiGmCF8wEARvH9Y+8xzOc869zznPvU0fnv/MM/vetffaZ+393y9rr73poYce/m/wRlyBu/A4hvD9Lup7Ib6NbdiLQXwRz64ovxi3Yyv24G/4IU4Z5htNdPJ4h2jnEN5bkr8Sd+DhVP9O/BErcHRFnU10BnN2FH/bK3TG4Xz8Bk/gP7gPF+CQCp26nDSxq+k46pTLdw1jU/Y7UFJ/XV6OFmPiejyUdB7D3XiP6j6GVye97aKft+E2nJUvNK6gtA5zBJlbcTyuFYO0Lmbg13gebsQGzMdCbMQr8e9c+ZW4JMluwA4ch7MxHu/UTmITnTyOwZ9xKI4Ug/nqQpl9+AMewD9xBE7Gy0WnniwI7VZnEM8Sk6GIJ3B5ifxavC194yfYjTPRh2tE+/Ooy0lTu5qMozpczsXSinpOwxm4Ba8r5NXl5QJciX/gTvwdU3EOjsKP8SYx4fO4DBentt+a2jIFL8PPUztLsRAzxcTs190OeFvS/0hBvirJv56TTRMr1nYxOIo2DYnVUJc6eYwTnfFXfEH1DjixQv9zSedro6QzmH6d4vVabXxuTv4M3JTyzino1OGkqV3UH0fdcpnHPan82SV5dXk5A0u073TTxGQcwhsKeecn+XcFF0VMqLChDf2aT8AZSXezduMna7lLRyTZglT+xor6HseugqyJTh4X4mm8CgOqJ2AV5iSd1aOkM6jeQP9equtDJXlzU94vcrK6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ugnintHVwisVd/fOsESEceeLWHW7WIRzRbKex7OJ19Q0ZpI4/N0llLhQeMs87hT3xM4QCh0ovOUG4TkX6pgMZ+daR4iYtwx367gwRiY+VUWGdtFErro6a6LjpvraJqqBl4uq2hj8W3iRuSIfy2OlOMc8RXjGo4VHWSPmcrGO9/nq8miClr+/eNeuF73oRQP01DlSL3rxf4VeQ+pFL7oB/wOm+BUgbC39HwAAAABJRU5ErkJggg==\n",
"text/latex": [
"$\\displaystyle 1.0884335905187326$"
"$\\displaystyle 0.983274288265642$"
],
"text/plain": [
"1.0884335905187326"
"0.983274288265642"
]
},
"execution_count": 9,
@ -308,7 +297,20 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.8.5"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": false,
"sideBar": true,
"skip_h1_title": true,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -268,7 +268,7 @@
}
],
"source": [
"identified_estimand = model.identify_effect()\n",
"identified_estimand = model.identify_effect(proceed_when_unidentifiable=True)\n",
"print(identified_estimand)"
]
},

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -136,7 +136,7 @@
" treatment='treat',\n",
" outcome='re78',\n",
" common_causes='nodegr+black+hisp+age+educ+married'.split('+'))\n",
"identified_estimand = model.identify_effect()\n",
"identified_estimand = model.identify_effect(proceed_when_unidentifiable=True)\n",
"estimate = model.estimate_effect(identified_estimand,\n",
" method_name=\"backdoor.propensity_score_weighting\",\n",
" method_params={\"weighting_scheme\":\"ips_weight\"})\n",

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -20,8 +20,6 @@
"metadata": {},
"outputs": [],
"source": [
"import os, sys\n",
"sys.path.append(os.path.abspath(\"../../../\"))\n",
"import pandas as pd\n",
"import numpy as np\n",
"import dowhy\n",
@ -418,27 +416,40 @@
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:dowhy.causal_identifier:Common causes of treatment and outcome:['gestat10', 'U']\n",
"WARNING:dowhy.causal_identifier:If this is observed data (not from a randomized experiment), there might always be missing confounders. Causal effect cannot be identified perfectly.\n"
"WARNING:dowhy.causal_identifier:If this is observed data (not from a randomized experiment), there might always be missing confounders. Causal effect cannot be identified perfectly.\n",
"INFO:dowhy.causal_identifier:Continuing by ignoring these unobserved confounders because proceed_when_unidentifiable flag is True.\n",
"INFO:dowhy.causal_identifier:Instrumental variables for treatment and outcome:[]\n",
"INFO:dowhy.causal_identifier:Frontdoor variables for treatment and outcome:[]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"WARN: Do you want to continue by ignoring any unobserved confounders? (use proceed_when_unidentifiable=True to disable this prompt) [y/n] y\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:dowhy.causal_identifier:Instrumental variables for treatment and outcome:[]\n"
"Estimand type: nonparametric-ate\n",
"\n",
"### Estimand : 1\n",
"Estimand name: backdoor1 (Default)\n",
"Estimand expression:\n",
" d \n",
"────────────(Expectation(outcome|gestat10))\n",
"d[treatment] \n",
"Estimand assumption 1, Unconfoundedness: If U→{treatment} and U→outcome then P(outcome|treatment,gestat10,U) = P(outcome|treatment,gestat10)\n",
"\n",
"### Estimand : 2\n",
"Estimand name: iv\n",
"No such variable found!\n",
"\n",
"### Estimand : 3\n",
"Estimand name: frontdoor\n",
"No such variable found!\n",
"\n"
]
}
],
"source": [
"identified_estimand = model.identify_effect()"
"identified_estimand = model.identify_effect(proceed_when_unidentifiable=True)\n",
"print(identified_estimand)"
]
},
{
@ -464,8 +475,8 @@
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:dowhy.causal_estimator:INFO: Using Linear Regression Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n"
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"INFO:dowhy.causal_estimator:INFO: Using Linear Regression Estimator\n"
]
},
{
@ -474,29 +485,19 @@
"text": [
"*** Causal Estimate ***\n",
"\n",
"## Target estimand\n",
"## Identified estimand\n",
"Estimand type: nonparametric-ate\n",
"### Estimand : 1\n",
"Estimand name: backdoor\n",
"Estimand expression:\n",
" d \n",
"────────────(Expectation(outcome|gestat10))\n",
"d[treatment] \n",
"Estimand assumption 1, Unconfoundedness: If U→{treatment} and U→outcome then P(outcome|treatment,gestat10,U) = P(outcome|treatment,gestat10)\n",
"### Estimand : 2\n",
"Estimand name: iv\n",
"No such variable found!\n",
"\n",
"## Realized estimand\n",
"b: outcome~treatment+gestat10\n",
"## Estimate\n",
"Value: -0.025200267022696315\n",
"Target units: ate\n",
"\n",
"## Statistical Significance\n",
"p-value: <0.001\n",
"## Estimate\n",
"Mean value: -0.025200267022700423\n",
"p-value: [7.18902894e-08]\n",
"\n",
"ATE -0.025200267022696926\n",
"Causal Estimate is -0.025200267022696315\n"
"Causal Estimate is -0.025200267022700423\n"
]
}
],
@ -528,8 +529,8 @@
"text": [
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/arshia/anaconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:760: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n"
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n"
]
},
{
@ -576,8 +577,8 @@
"text": [
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10+w_random\n",
"/home/arshia/anaconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:760: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n"
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n"
]
},
{
@ -585,8 +586,8 @@
"output_type": "stream",
"text": [
"Refute: Add a Random Common Cause\n",
"Estimated effect:(-0.012600133511348465,)\n",
"New effect:(-0.02891355140186916,)\n",
"Estimated effect:-0.012600133511348465\n",
"New effect:-0.025826101468624834\n",
"\n"
]
}
@ -613,10 +614,89 @@
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:dowhy.causal_refuters.placebo_treatment_refuter:Refutation over 20 simulated datasets of permute treatment\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/arshia/anaconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:760: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n"
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~placebo+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"WARNING:dowhy.causal_refuters.placebo_treatment_refuter:We assume a Normal Distribution as the sample has less than 100 examples.\n",
" Note: The underlying distribution may not be Normal. We assume that it approaches normal with the increase in sample size.\n"
]
},
{
@ -624,15 +704,17 @@
"output_type": "stream",
"text": [
"Refute: Use a Placebo Treatment\n",
"Estimated effect:(-0.012600133511348465,)\n",
"New effect:(-0.16384345794392524,)\n",
"Estimated effect:-0.012600133511348465\n",
"New effect:0.06444843124165553\n",
"p value:0.31698886663194925\n",
"\n"
]
}
],
"source": [
"res_placebo=model.refute_estimate(identified_estimand, estimate,\n",
" method_name=\"placebo_treatment_refuter\", placebo_type=\"permute\")\n",
" method_name=\"placebo_treatment_refuter\", placebo_type=\"permute\",\n",
" num_simulations=20) \n",
"print(res_placebo)"
]
},
@ -652,10 +734,89 @@
"name": "stderr",
"output_type": "stream",
"text": [
"INFO:dowhy.causal_refuters.data_subset_refuter:Refutation over 0.9 simulated datasets of size 21571.2 each\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/arshia/anaconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:760: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" y = column_or_1d(y, warn=True)\n"
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"INFO:dowhy.causal_estimator:INFO: Using Propensity Score Matching Estimator\n",
"INFO:dowhy.causal_estimator:b: outcome~treatment+gestat10\n",
"/home/amit/py-envs/env3.8/lib/python3.8/site-packages/sklearn/utils/validation.py:72: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
" return f(**kwargs)\n",
"WARNING:dowhy.causal_refuters.data_subset_refuter:We assume a Normal Distribution as the sample has less than 100 examples.\n",
" Note: The underlying distribution may not be Normal. We assume that it approaches normal with the increase in sample size.\n"
]
},
{
@ -663,24 +824,19 @@
"output_type": "stream",
"text": [
"Refute: Use a subset of data\n",
"Estimated effect:(-0.012600133511348465,)\n",
"New effect:(0.15136062305873627,)\n",
"Estimated effect:-0.012600133511348465\n",
"New effect:-0.08120856705762365\n",
"p value:0.21986894766211718\n",
"\n"
]
}
],
"source": [
"res_subset=model.refute_estimate(identified_estimand, estimate,\n",
" method_name=\"data_subset_refuter\", subset_fraction=0.9)\n",
" method_name=\"data_subset_refuter\", subset_fraction=0.9,\n",
" num_simulations=20)\n",
"print(res_subset)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -739,10 +739,11 @@ class CausalEstimate:
s += "\n## Estimate\n"
s += "Mean value: {0}\n".format(self.value)
s += ""
if hasattr(self, "cate_estimates"):
s += "Effect estimates: {0}\n".format(self.cate_estimates)
if self.estimator._significance_test:
s += "p-value: {0}\n".format(self.estimator.signif_results_tostr(self.test_stat_significance()))
if self.estimator._confidence_intervals:
s += "Standard error: {0}\n".format(self.get_standard_error())
s += "{0}% confidence interval: {1}\n".format(100 * self.estimator.confidence_level, self.get_confidence_intervals())
if self.conditional_estimates is not None:
s += "### Conditional Estimates\n"

Просмотреть файл

@ -102,17 +102,24 @@ class Econml(CausalEstimator):
est = self.estimator.effect(X_test, T0=T0_test, T1=T1_test)
ate = np.mean(est)
est_interval = None
self.effect_intervals = None
if self._confidence_intervals:
est_interval = self.estimator.effect_interval(X_test, T0=T0_test, T1=T1_test)
self.effect_intervals = self.estimator.effect_interval(
X_test, T0=T0_test, T1=T1_test,
alpha=1-self.confidence_level)
estimate = CausalEstimate(estimate=ate,
target_estimand=self._target_estimand,
realized_estimand_expr=self.symbolic_estimator,
cate_estimates=est,
effect_intervals=est_interval,
effect_intervals=self.effect_intervals,
_estimator_object=self.estimator)
return estimate
def _estimate_confidence_intervals(self, confidence_level=None, method=None):
""" Returns None if the confidence interval has not been calculated.
"""
return self.effect_intervals
def _do(self, x):
raise NotImplementedError

Просмотреть файл

@ -23,12 +23,16 @@ class CausalIdentifier:
NONPARAMETRIC_ATE="nonparametric-ate"
NONPARAMETRIC_NDE="nonparametric-nde"
NONPARAMETRIC_NIE="nonparametric-nie"
MAX_BACKDOOR_ITERATIONS = 100000
def __init__(self, graph, estimand_type, proceed_when_unidentifiable=False):
def __init__(self, graph, estimand_type,
method_name = None,
proceed_when_unidentifiable=False):
self._graph = graph
self.estimand_type = estimand_type
self.treatment_name = graph.treatment_name
self.outcome_name = graph.outcome_name
self.method_name = method_name
self._proceed_when_unidentifiable = proceed_when_unidentifiable
self.logger = logging.getLogger(__name__)
@ -246,6 +250,27 @@ class CausalIdentifier:
- set(outcome_name) \
- set(self._graph.get_instruments(treatment_name, outcome_name))
eligible_variables -= self._graph.get_descendants(treatment_name)
num_iterations = 0
found_valid_adjustment_set = False
if self.method_name == "auto":
for size_candidate_set in range(len(eligible_variables), 0, -1):
for candidate_set in itertools.combinations(eligible_variables, size_candidate_set):
check = self._graph.check_valid_backdoor_set(treatment_name,
outcome_name, candidate_set, backdoor_paths=backdoor_paths)
self.logger.debug("Candidate backdoor set: {0}, is_dseparated: {1}, No. of paths blocked by observed_nodes: {2}".format(candidate_set, check["is_dseparated"], check["num_paths_blocked_by_observed_nodes"]))
if check["is_dseparated"]:
backdoor_sets.append({
'backdoor_set': candidate_set,
'num_paths_blocked_by_observed_nodes': check["num_paths_blocked_by_observed_nodes"]})
if self._graph.all_observed(candidate_set):
found_valid_adjustment_set = True
num_iterations += 1
if num_iterations > CausalIdentifier.MAX_BACKDOOR_ITERATIONS:
break
if found_valid_adjustment_set:
break
elif self.method_name == "exhaustive-search":
for size_candidate_set in range(1, len(eligible_variables)+1):
for candidate_set in itertools.combinations(eligible_variables, size_candidate_set):
check = self._graph.check_valid_backdoor_set(treatment_name,
@ -255,7 +280,8 @@ class CausalIdentifier:
backdoor_sets.append({
'backdoor_set': candidate_set,
'num_paths_blocked_by_observed_nodes': check["num_paths_blocked_by_observed_nodes"]})
else:
raise ValueError("Identifier method " + self.method_name + "not supported. Try 'default' or 'exhaustive-search'.")
#causes_t = self._graph.get_causes(self.treatment_name)
#causes_y = self._graph.get_causes(self.outcome_name, remove_edges={'sources':self.treatment_name, 'targets':self.outcome_name})
#common_causes = list(causes_t.intersection(causes_y))

Просмотреть файл

@ -126,7 +126,8 @@ class CausalModel:
self._other_variables = kwargs
self.summary()
def identify_effect(self, estimand_type=None, proceed_when_unidentifiable=None):
def identify_effect(self, estimand_type=None,
method_name="auto", proceed_when_unidentifiable=None):
"""Identify the causal effect to be estimated, using properties of the causal graph.
:param proceed_when_unidentifiable: Binary flag indicating whether identification should proceed in the presence of (potential) unobserved confounders.
@ -140,6 +141,7 @@ class CausalModel:
self.identifier = CausalIdentifier(self._graph,
estimand_type,
method_name,
proceed_when_unidentifiable=proceed_when_unidentifiable)
identified_estimand = self.identifier.identify_effect()

75
tests/test_notebooks.py Normal file
Просмотреть файл

@ -0,0 +1,75 @@
import os
import subprocess
import tempfile
import nbformat
import pytest
NOTEBOOKS_PATH = "docs/source/example_notebooks/"
notebooks_list = [ f.name for f in os.scandir(NOTEBOOKS_PATH) if f.name.endswith(".ipynb")]
advanced_notebooks = [
# requires stdin input for identify in weighting sampler
"do_sampler_demo.ipynb",
# requires Rpy2 for lalonde
"dowhy_refutation_testing.ipynb",
"dowhy_lalonde_example.ipynb",
"lalonde_pandas_api.ipynb",
# very slow
"dowhy-conditional-treatment-effects.ipynb",
"dowhy_refuter_notebook.ipynb",
"DoWhy-The Causal Story Behind Hotel Booking Cancellations.ipynb", # needs xgboost too
]
# Adding the dowhy root folder to the python path so that jupyter notebooks
# can import dowhy
if 'PYTHONPATH' not in os.environ:
os.environ['PYTHONPATH'] = os.getcwd()
elif os.getcwd() not in os.environ['PYTHONPATH'].split(os.pathsep):
os.environ['PYTHONPATH'] = os.environ['PYTHONPATH'] + os.pathsep + os.getcwd()
def _notebook_run(filepath):
"""Execute a notebook via nbconvert and collect output.
:returns (parsed nb object, execution errors)
Source of this function: http://www.christianmoscardi.com/blog/2016/01/20/jupyter-testing.html
"""
with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout:
args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
# "--ExecutePreprocessor.timeout=600",
"-y", "--no-prompt",
"--output", fout.name, filepath]
subprocess.check_call(args)
fout.seek(0)
nb = nbformat.read(fout, nbformat.current_nbformat)
errors = [output for cell in nb.cells if "outputs" in cell
for output in cell["outputs"]\
if output.output_type == "error"]
return nb, errors
"""
def test_getstarted_notebook():
nb, errors = _notebook_run(NOTEBOOKS_PATH+ "dowhy_simple_example.ipynb")
assert errors == []
def test_confounder_notebook():
nb, errors = _notebook_run(NOTEBOOKS_PATH+"dowhy_confounder_example.ipynb")
assert errors = []
"""
parameter_list=[]
for nb in notebooks_list:
if nb in advanced_notebooks:
param = pytest.param(nb,
marks=[pytest.mark.skip, pytest.mark.advanced],
id=nb)
else:
param = pytest.param(nb, id=nb)
parameter_list.append(param)
@pytest.mark.parametrize("notebook_filename", parameter_list)
def test_notebook(notebook_filename):
nb, errors = _notebook_run(NOTEBOOKS_PATH + notebook_filename)
assert errors == []