Rename classes in test folder
The TestEstimator and TestRefuter were falsely interpreted as unit test classes due to their "Test" prefix. Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
This commit is contained in:
Родитель
711e6ba902
Коммит
1f9ee6be46
|
@ -5,7 +5,7 @@ from dowhy import EstimandType, identify_effect_auto
|
|||
from dowhy.graph import build_graph_from_str
|
||||
|
||||
|
||||
class TestEstimator(object):
|
||||
class SimpleEstimator(object):
|
||||
def __init__(self, error_tolerance, Estimator, identifier_method="backdoor"):
|
||||
print("Error tolerance is", error_tolerance)
|
||||
self._error_tolerance = error_tolerance
|
||||
|
|
|
@ -1 +1 @@
|
|||
from dowhy.causal_estimators.propensity_score_weighting_estimator import PropensityScoreWeightingEstimator
|
||||
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
from pytest import mark
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import itertools
|
||||
import re
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import pytest
|
||||
from sklearn.ensemble import GradientBoostingClassifier, GradientBoostingRegressor
|
||||
from sklearn.linear_model import LogisticRegression, LogisticRegressionCV
|
||||
from sklearn.linear_model import LogisticRegressionCV
|
||||
from sklearn.model_selection import train_test_split
|
||||
from sklearn.preprocessing import PolynomialFeatures
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
import pytest
|
||||
import statsmodels.api as sm
|
||||
from pytest import mark
|
||||
|
||||
from dowhy.causal_estimators.generalized_linear_model_estimator import GeneralizedLinearModelEstimator
|
||||
|
||||
from .base import TestEstimator
|
||||
from .base import SimpleEstimator
|
||||
|
||||
|
||||
@mark.usefixtures("fixed_seed")
|
||||
|
@ -59,7 +58,7 @@ class TestGeneralizedLinearModelEstimator(object):
|
|||
outcome_is_binary,
|
||||
identifier_method,
|
||||
):
|
||||
estimator_tester = TestEstimator(error_tolerance, Estimator, identifier_method)
|
||||
estimator_tester = SimpleEstimator(error_tolerance, Estimator, identifier_method)
|
||||
estimator_tester.average_treatment_effect_testsuite(
|
||||
num_common_causes=num_common_causes,
|
||||
num_instruments=num_instruments,
|
||||
|
|
|
@ -5,7 +5,7 @@ from pytest import mark
|
|||
|
||||
from dowhy.causal_estimators.instrumental_variable_estimator import InstrumentalVariableEstimator
|
||||
|
||||
from .base import TestEstimator
|
||||
from .base import SimpleEstimator
|
||||
|
||||
|
||||
@mark.usefixtures("fixed_seed")
|
||||
|
@ -52,7 +52,7 @@ class TestInstrumentalVariableEstimator(object):
|
|||
outcome_is_binary,
|
||||
identifier_method,
|
||||
):
|
||||
estimator_tester = TestEstimator(error_tolerance, Estimator, identifier_method=identifier_method)
|
||||
estimator_tester = SimpleEstimator(error_tolerance, Estimator, identifier_method=identifier_method)
|
||||
# Not using testsuite from .base/TestEstimtor, custom code below
|
||||
args_dict = {
|
||||
"num_common_causes": num_common_causes,
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import pytest
|
||||
from pytest import mark
|
||||
|
||||
from dowhy.causal_estimators.linear_regression_estimator import LinearRegressionEstimator
|
||||
|
||||
from .base import TestEstimator
|
||||
from .base import SimpleEstimator
|
||||
|
||||
|
||||
@mark.usefixtures("fixed_seed")
|
||||
|
@ -92,7 +91,7 @@ class TestLinearRegressionEstimator(object):
|
|||
treatment_is_category,
|
||||
outcome_is_binary,
|
||||
):
|
||||
estimator_tester = TestEstimator(error_tolerance, Estimator)
|
||||
estimator_tester = SimpleEstimator(error_tolerance, Estimator)
|
||||
estimator_tester.average_treatment_effect_testsuite(
|
||||
num_common_causes=num_common_causes,
|
||||
num_instruments=num_instruments,
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import pytest
|
||||
from pytest import mark
|
||||
|
||||
from dowhy.causal_estimators.propensity_score_matching_estimator import PropensityScoreMatchingEstimator
|
||||
|
||||
from .base import TestEstimator
|
||||
from .base import SimpleEstimator
|
||||
|
||||
|
||||
@mark.usefixtures("fixed_seed")
|
||||
|
@ -51,7 +50,7 @@ class TestPropensityScoreMatchingEstimator(object):
|
|||
treatment_is_binary,
|
||||
outcome_is_binary,
|
||||
):
|
||||
estimator_tester = TestEstimator(error_tolerance, Estimator)
|
||||
estimator_tester = SimpleEstimator(error_tolerance, Estimator)
|
||||
estimator_tester.average_treatment_effect_testsuite(
|
||||
num_common_causes=num_common_causes,
|
||||
num_instruments=num_instruments,
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import pytest
|
||||
from pytest import mark
|
||||
|
||||
from dowhy.causal_estimators.propensity_score_stratification_estimator import PropensityScoreStratificationEstimator
|
||||
|
||||
from .base import TestEstimator
|
||||
from .base import SimpleEstimator
|
||||
|
||||
|
||||
@mark.usefixtures("fixed_seed")
|
||||
|
@ -51,7 +50,7 @@ class TestPropensityScoreStratificationEstimator(object):
|
|||
treatment_is_binary,
|
||||
outcome_is_binary,
|
||||
):
|
||||
estimator_tester = TestEstimator(error_tolerance, Estimator)
|
||||
estimator_tester = SimpleEstimator(error_tolerance, Estimator)
|
||||
estimator_tester.average_treatment_effect_testsuite(
|
||||
num_common_causes=num_common_causes,
|
||||
num_instruments=num_instruments,
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
import numpy as np
|
||||
import pytest
|
||||
from pytest import mark
|
||||
from sklearn.linear_model import LinearRegression
|
||||
|
||||
import dowhy.api
|
||||
from dowhy.causal_estimators.propensity_score_weighting_estimator import PropensityScoreWeightingEstimator
|
||||
|
||||
from .base import TestEstimator
|
||||
from .base import SimpleEstimator
|
||||
|
||||
|
||||
@mark.usefixtures("fixed_seed")
|
||||
|
@ -54,7 +50,7 @@ class TestPropensityScoreWeightingEstimator(object):
|
|||
treatment_is_binary,
|
||||
outcome_is_binary,
|
||||
):
|
||||
estimator_tester = TestEstimator(error_tolerance, Estimator)
|
||||
estimator_tester = SimpleEstimator(error_tolerance, Estimator)
|
||||
estimator_tester.average_treatment_effect_testsuite(
|
||||
num_common_causes=num_common_causes,
|
||||
num_instruments=num_instruments,
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import pytest
|
||||
from pytest import mark
|
||||
|
||||
from dowhy.causal_estimators.regression_discontinuity_estimator import RegressionDiscontinuityEstimator
|
||||
|
||||
from .base import TestEstimator
|
||||
from .base import SimpleEstimator
|
||||
|
||||
|
||||
@mark.usefixtures("fixed_seed")
|
||||
|
@ -54,7 +53,7 @@ class TestRegressionDiscontinuityEstimator(object):
|
|||
outcome_is_binary,
|
||||
identifier_method,
|
||||
):
|
||||
estimator_tester = TestEstimator(error_tolerance, Estimator, identifier_method=identifier_method)
|
||||
estimator_tester = SimpleEstimator(error_tolerance, Estimator, identifier_method=identifier_method)
|
||||
estimator_tester.average_treatment_effect_testsuite(
|
||||
num_common_causes=num_common_causes,
|
||||
num_instruments=num_instruments,
|
||||
|
|
|
@ -6,7 +6,7 @@ from pytest import mark
|
|||
from dowhy import CausalModel
|
||||
from dowhy.causal_estimators.two_stage_regression_estimator import TwoStageRegressionEstimator
|
||||
|
||||
from .base import TestEstimator
|
||||
from .base import SimpleEstimator
|
||||
|
||||
|
||||
@mark.usefixtures("fixed_seed")
|
||||
|
@ -57,7 +57,7 @@ class TestTwoStageRegressionEstimator(object):
|
|||
treatment_is_binary,
|
||||
outcome_is_binary,
|
||||
):
|
||||
estimator_tester = TestEstimator(error_tolerance, Estimator, identifier_method="frontdoor")
|
||||
estimator_tester = SimpleEstimator(error_tolerance, Estimator, identifier_method="frontdoor")
|
||||
estimator_tester.average_treatment_effect_testsuite(
|
||||
num_common_causes=num_common_causes,
|
||||
num_instruments=num_instruments,
|
||||
|
@ -159,7 +159,7 @@ class TestTwoStageRegressionEstimator(object):
|
|||
],
|
||||
)
|
||||
def test_frontdoor_num_variables_error(self, Estimator, num_treatments, num_frontdoor_variables):
|
||||
estimator_tester = TestEstimator(error_tolerance=0, Estimator=Estimator, identifier_method="frontdoor")
|
||||
estimator_tester = SimpleEstimator(error_tolerance=0, Estimator=Estimator, identifier_method="frontdoor")
|
||||
with pytest.raises((ValueError, Exception)):
|
||||
estimator_tester.average_treatment_effect_testsuite(
|
||||
num_common_causes=[1, 1],
|
||||
|
|
|
@ -4,7 +4,7 @@ import dowhy.datasets
|
|||
from dowhy import CausalModel
|
||||
|
||||
|
||||
class TestRefuter(object):
|
||||
class SimpleRefuter(object):
|
||||
def __init__(
|
||||
self,
|
||||
error_tolerance,
|
||||
|
|
|
@ -5,14 +5,12 @@ import pytest
|
|||
import statsmodels.api as sm
|
||||
from pytest import mark
|
||||
from sklearn.ensemble import GradientBoostingRegressor
|
||||
from sklearn.linear_model import LassoCV
|
||||
from sklearn.preprocessing import PolynomialFeatures
|
||||
|
||||
import dowhy.datasets
|
||||
from dowhy import CausalModel
|
||||
from dowhy.causal_refuters.evalue_sensitivity_analyzer import EValueSensitivityAnalyzer
|
||||
|
||||
from .base import TestRefuter
|
||||
from .base import SimpleRefuter
|
||||
|
||||
|
||||
@mark.usefixtures("fixed_seed")
|
||||
|
@ -26,7 +24,7 @@ class TestAddUnobservedCommonCauseRefuter(object):
|
|||
def test_refutation_binary_treatment(
|
||||
self, error_tolerance, estimator_method, effect_strength_on_t, effect_strength_on_y
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerance,
|
||||
estimator_method,
|
||||
"add_unobserved_common_cause",
|
||||
|
@ -46,7 +44,7 @@ class TestAddUnobservedCommonCauseRefuter(object):
|
|||
def test_refutation_continuous_treatment(
|
||||
self, error_tolerance, estimator_method, effect_strength_on_t, effect_strength_on_y
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerance,
|
||||
estimator_method,
|
||||
"add_unobserved_common_cause",
|
||||
|
@ -67,7 +65,7 @@ class TestAddUnobservedCommonCauseRefuter(object):
|
|||
def test_refutation_continuous_treatment_range_both_treatment_outcome(
|
||||
self, mock_fig, error_tolerance, estimator_method, effect_strength_on_t, effect_strength_on_y
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerance,
|
||||
estimator_method,
|
||||
"add_unobserved_common_cause",
|
||||
|
@ -89,7 +87,7 @@ class TestAddUnobservedCommonCauseRefuter(object):
|
|||
def test_refutation_continuous_treatment_range_treatment(
|
||||
self, mock_fig, error_tolerance, estimator_method, effect_strength_on_t, effect_strength_on_y
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerance,
|
||||
estimator_method,
|
||||
"add_unobserved_common_cause",
|
||||
|
@ -111,7 +109,7 @@ class TestAddUnobservedCommonCauseRefuter(object):
|
|||
def test_refutation_continuous_treatment_range_outcome(
|
||||
self, mock_fig, error_tolerance, estimator_method, effect_strength_on_t, effect_strength_on_y
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerance,
|
||||
estimator_method,
|
||||
"add_unobserved_common_cause",
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import numpy as np
|
||||
import pytest
|
||||
from pytest import mark
|
||||
|
||||
from .base import TestRefuter
|
||||
from .base import SimpleRefuter
|
||||
|
||||
|
||||
@mark.usefixtures("fixed_seed")
|
||||
|
@ -17,14 +15,14 @@ class TestDataSubsetRefuter(object):
|
|||
["error_tolerance", "estimator_method", "num_samples"], [(0.05, "iv.instrumental_variable", 1000)]
|
||||
)
|
||||
def test_refutation_bootstrap_refuter_continuous(self, error_tolerance, estimator_method, num_samples):
|
||||
refuter_tester = TestRefuter(error_tolerance, estimator_method, "bootstrap_refuter")
|
||||
refuter_tester = SimpleRefuter(error_tolerance, estimator_method, "bootstrap_refuter")
|
||||
refuter_tester.continuous_treatment_testsuite(num_samples=num_samples) # Run both
|
||||
|
||||
@mark.parametrize(
|
||||
["error_tolerance", "estimator_method", "num_samples"], [(0.05, "backdoor.propensity_score_matching", 1000)]
|
||||
)
|
||||
def test_refutation_bootstrap_refuter_binary(self, error_tolerance, estimator_method, num_samples):
|
||||
refuter_tester = TestRefuter(error_tolerance, estimator_method, "bootstrap_refuter")
|
||||
refuter_tester = SimpleRefuter(error_tolerance, estimator_method, "bootstrap_refuter")
|
||||
refuter_tester.binary_treatment_testsuite(tests_to_run="atleast-one-common-cause", num_samples=num_samples)
|
||||
|
||||
@mark.parametrize(
|
||||
|
@ -34,7 +32,7 @@ class TestDataSubsetRefuter(object):
|
|||
def test_refutation_bootstrap_refuter_continuous_integer_argument(
|
||||
self, error_tolerance, estimator_method, num_common_causes, required_variables, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerance,
|
||||
estimator_method,
|
||||
"bootstrap_refuter",
|
||||
|
@ -51,7 +49,7 @@ class TestDataSubsetRefuter(object):
|
|||
def test_refutation_bootstrap_refuter_continuous_list_argument(
|
||||
self, error_tolerance, estimator_method, num_common_causes, required_variables, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerance, estimator_method, "bootstrap_refuter", required_variables=required_variables
|
||||
)
|
||||
refuter_tester.continuous_treatment_testsuite(
|
||||
|
@ -65,7 +63,7 @@ class TestDataSubsetRefuter(object):
|
|||
def test_refutation_bootstrap_refuter_binary_integer_argument(
|
||||
self, error_tolerance, estimator_method, num_common_causes, required_variables, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerance, estimator_method, "bootstrap_refuter", required_variables=required_variables
|
||||
)
|
||||
refuter_tester.binary_treatment_testsuite(
|
||||
|
@ -79,7 +77,7 @@ class TestDataSubsetRefuter(object):
|
|||
def test_refutation_bootstrap_refuter_binary_list_argument(
|
||||
self, error_tolerance, estimator_method, num_common_causes, required_variables, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerance, estimator_method, "bootstrap_refuter", required_variables=required_variables
|
||||
)
|
||||
refuter_tester.binary_treatment_testsuite(
|
||||
|
@ -93,7 +91,7 @@ class TestDataSubsetRefuter(object):
|
|||
def test_refutation_bootstrap_refuter_continuous_list_negative_argument(
|
||||
self, error_tolerance, estimator_method, num_common_causes, required_variables, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerance, estimator_method, "bootstrap_refuter", required_variables=required_variables
|
||||
)
|
||||
refuter_tester.continuous_treatment_testsuite(
|
||||
|
@ -107,7 +105,7 @@ class TestDataSubsetRefuter(object):
|
|||
def test_refutation_bootstrap_refuter_binary_list_negative_argument(
|
||||
self, error_tolerance, estimator_method, num_common_causes, required_variables, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerance, estimator_method, "bootstrap_refuter", required_variables=required_variables
|
||||
)
|
||||
refuter_tester.binary_treatment_testsuite(
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
import numpy as np
|
||||
from pytest import mark
|
||||
|
||||
from .base import TestRefuter
|
||||
from .base import SimpleRefuter
|
||||
|
||||
|
||||
@mark.usefixtures("fixed_seed")
|
||||
class TestDataSubsetRefuter(object):
|
||||
@mark.parametrize(["error_tolerance", "estimator_method"], [(0.01, "iv.instrumental_variable")])
|
||||
def test_refutation_data_subset_refuter_continuous(self, error_tolerance, estimator_method):
|
||||
refuter_tester = TestRefuter(error_tolerance, estimator_method, "data_subset_refuter")
|
||||
refuter_tester = SimpleRefuter(error_tolerance, estimator_method, "data_subset_refuter")
|
||||
refuter_tester.continuous_treatment_testsuite() # Run both
|
||||
|
||||
@mark.parametrize(["error_tolerance", "estimator_method"], [(0.01, "backdoor.propensity_score_matching")])
|
||||
def test_refutation_data_subset_refuter_binary(self, error_tolerance, estimator_method):
|
||||
refuter_tester = TestRefuter(error_tolerance, estimator_method, "data_subset_refuter")
|
||||
refuter_tester = SimpleRefuter(error_tolerance, estimator_method, "data_subset_refuter")
|
||||
refuter_tester.binary_treatment_testsuite(tests_to_run="atleast-one-common-cause")
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
import pdb
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
from pytest import mark
|
||||
|
||||
from .base import TestRefuter
|
||||
from .base import SimpleRefuter
|
||||
|
||||
|
||||
def simple_linear_outcome_model(X_train, output_train):
|
||||
|
@ -17,7 +13,7 @@ def simple_linear_outcome_model(X_train, output_train):
|
|||
class TestDummyOutcomeRefuter(object):
|
||||
@mark.parametrize(["error_tolerence", "estimator_method"], [(0.03, "iv.instrumental_variable")])
|
||||
def test_refutation_dummy_outcome_refuter_default_continuous_treatment(self, error_tolerence, estimator_method):
|
||||
refuter_tester = TestRefuter(error_tolerence, estimator_method, "dummy_outcome_refuter")
|
||||
refuter_tester = SimpleRefuter(error_tolerence, estimator_method, "dummy_outcome_refuter")
|
||||
refuter_tester.continuous_treatment_testsuite(num_dummyoutcome_simulations=100)
|
||||
|
||||
@mark.parametrize(
|
||||
|
@ -26,7 +22,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_default_binary_treatment(
|
||||
self, error_tolerence, estimator_method, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(error_tolerence, estimator_method, "dummy_outcome_refuter")
|
||||
refuter_tester = SimpleRefuter(error_tolerence, estimator_method, "dummy_outcome_refuter")
|
||||
refuter_tester.binary_treatment_testsuite(tests_to_run="atleast-one-common-cause", num_samples=num_samples)
|
||||
|
||||
@mark.parametrize(
|
||||
|
@ -36,7 +32,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_randomly_generated_continuous_treatment(
|
||||
self, error_tolerence, estimator_method, transformations
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
|
||||
|
@ -49,7 +45,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_randomly_generated_binary_treatment(
|
||||
self, error_tolerence, estimator_method, transformations, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
|
||||
|
@ -62,7 +58,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_permute_data_continuous_treatment(
|
||||
self, error_tolerence, estimator_method, transformations
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
|
||||
|
@ -75,7 +71,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_permute_data_binary_treatment(
|
||||
self, error_tolerence, estimator_method, transformations, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
|
||||
|
@ -88,7 +84,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_custom_function_linear_regression_with_noise_continuous_treatment(
|
||||
self, error_tolerence, estimator_method, transformations
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
refuter_tester.continuous_treatment_testsuite(tests_to_run="atleast-one-common-cause")
|
||||
|
@ -101,7 +97,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_custom_function_linear_regression_with_noise_binary_treatment(
|
||||
self, error_tolerence, estimator_method, transformations, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
refuter_tester.binary_treatment_testsuite(tests_to_run="atleast-one-common-cause", num_samples=num_samples)
|
||||
|
@ -119,7 +115,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_custom_function_linear_regression_with_permute_continuous_treatment(
|
||||
self, error_tolerence, estimator_method, transformations
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
refuter_tester.continuous_treatment_testsuite(tests_to_run="atleast-one-common-cause")
|
||||
|
@ -139,7 +135,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_custom_function_linear_regression_with_permute_binary_treatment(
|
||||
self, error_tolerence, estimator_method, transformations, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
refuter_tester.binary_treatment_testsuite(tests_to_run="atleast-one-common-cause", num_samples=num_samples)
|
||||
|
@ -151,7 +147,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_internal_linear_regression_continuous_treatment(
|
||||
self, error_tolerence, estimator_method, transformations
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
refuter_tester.continuous_treatment_testsuite(tests_to_run="atleast-one-common-cause")
|
||||
|
@ -170,7 +166,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_internal_linear_regression_binary_treatment(
|
||||
self, error_tolerence, estimator_method, transformations, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
refuter_tester.binary_treatment_testsuite(tests_to_run="atleast-one-common-cause", num_samples=num_samples)
|
||||
|
@ -182,7 +178,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_internal_knn_continuous_treatment(
|
||||
self, error_tolerence, estimator_method, transformations
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
refuter_tester.continuous_treatment_testsuite(tests_to_run="atleast-one-common-cause")
|
||||
|
@ -201,7 +197,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_internal_knn_binary_treatment(
|
||||
self, error_tolerence, estimator_method, transformations, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
refuter_tester.binary_treatment_testsuite(tests_to_run="atleast-one-common-cause", num_samples=num_samples)
|
||||
|
@ -220,7 +216,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_internal_svm_continuous_treatment(
|
||||
self, error_tolerence, estimator_method, transformations, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
refuter_tester.continuous_treatment_testsuite(num_samples=num_samples, tests_to_run="atleast-one-common-cause")
|
||||
|
@ -239,7 +235,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_internal_svm_binary_treatment(
|
||||
self, error_tolerence, estimator_method, transformations, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
refuter_tester.binary_treatment_testsuite(num_samples=num_samples, tests_to_run="atleast-one-common-cause")
|
||||
|
@ -258,7 +254,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_internal_random_forest_continuous_treatment(
|
||||
self, error_tolerence, estimator_method, transformations, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
refuter_tester.continuous_treatment_testsuite(num_samples, tests_to_run="atleast-one-common-cause")
|
||||
|
@ -277,7 +273,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_internal_random_forest_binary_treatment(
|
||||
self, error_tolerence, estimator_method, transformations, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
refuter_tester.binary_treatment_testsuite(num_samples, tests_to_run="atleast-one-common-cause")
|
||||
|
@ -300,7 +296,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_internal_neural_network_continuous_treatment(
|
||||
self, error_tolerence, estimator_method, transformations
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
refuter_tester.continuous_treatment_testsuite(tests_to_run="atleast-one-common-cause")
|
||||
|
@ -323,7 +319,7 @@ class TestDummyOutcomeRefuter(object):
|
|||
def test_refutation_dummy_outcome_refuter_internal_neural_network_binary_treatment(
|
||||
self, error_tolerence, estimator_method, transformations, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(
|
||||
refuter_tester = SimpleRefuter(
|
||||
error_tolerence, estimator_method, "dummy_outcome_refuter", transformations=transformations
|
||||
)
|
||||
refuter_tester.binary_treatment_testsuite(num_samples=num_samples, tests_to_run="atleast-one-common-cause")
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
import random
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
from pytest import mark
|
||||
|
||||
import dowhy.datasets
|
||||
|
||||
from .base import TestRefuter
|
||||
from .base import SimpleRefuter
|
||||
|
||||
|
||||
@mark.usefixtures("fixed_seed")
|
||||
|
@ -15,21 +13,21 @@ class TestPlaceboRefuter(object):
|
|||
["error_tolerance", "estimator_method", "num_samples"], [(0.03, "backdoor.linear_regression", 1000)]
|
||||
)
|
||||
def test_refutation_placebo_refuter_continuous(self, error_tolerance, estimator_method, num_samples):
|
||||
refuter_tester = TestRefuter(error_tolerance, estimator_method, "placebo_treatment_refuter")
|
||||
refuter_tester = SimpleRefuter(error_tolerance, estimator_method, "placebo_treatment_refuter")
|
||||
refuter_tester.continuous_treatment_testsuite(num_samples=num_samples) # Run both
|
||||
|
||||
@mark.parametrize(
|
||||
["error_tolerance", "estimator_method", "num_samples"], [(0.1, "backdoor.propensity_score_matching", 5000)]
|
||||
)
|
||||
def test_refutation_placebo_refuter_binary(self, error_tolerance, estimator_method, num_samples):
|
||||
refuter_tester = TestRefuter(error_tolerance, estimator_method, "placebo_treatment_refuter")
|
||||
refuter_tester = SimpleRefuter(error_tolerance, estimator_method, "placebo_treatment_refuter")
|
||||
refuter_tester.binary_treatment_testsuite(tests_to_run="atleast-one-common-cause", num_samples=num_samples)
|
||||
|
||||
@mark.parametrize(
|
||||
["error_tolerance", "estimator_method", "num_samples"], [(0.1, "backdoor.linear_regression", 5000)]
|
||||
)
|
||||
def test_refutation_placebo_refuter_category(self, error_tolerance, estimator_method, num_samples):
|
||||
refuter_tester = TestRefuter(error_tolerance, estimator_method, "placebo_treatment_refuter")
|
||||
refuter_tester = SimpleRefuter(error_tolerance, estimator_method, "placebo_treatment_refuter")
|
||||
refuter_tester.categorical_treatment_testsuite(tests_to_run="atleast-one-common-cause", num_samples=num_samples)
|
||||
|
||||
@mark.parametrize(
|
||||
|
@ -38,7 +36,7 @@ class TestPlaceboRefuter(object):
|
|||
def test_refutation_placebo_refuter_category_non_consecutive_index(
|
||||
self, error_tolerance, estimator_method, num_samples
|
||||
):
|
||||
refuter_tester = TestRefuter(error_tolerance, estimator_method, "placebo_treatment_refuter")
|
||||
refuter_tester = SimpleRefuter(error_tolerance, estimator_method, "placebo_treatment_refuter")
|
||||
data = dowhy.datasets.linear_dataset(
|
||||
beta=10,
|
||||
num_common_causes=1,
|
||||
|
|
|
@ -123,7 +123,7 @@ def test_given_continuous_and_categorical_variables_when_get_noise_dependent_fun
|
|||
X1 = np.random.choice(2, 1000).astype(str)
|
||||
|
||||
X2 = []
|
||||
for (x0, x1) in zip(X0, X1):
|
||||
for x0, x1 in zip(X0, X1):
|
||||
if x1 == "0":
|
||||
x = np.random.normal(0, 1)
|
||||
else:
|
||||
|
|
|
@ -43,11 +43,11 @@ def test_when_fitting_normal_scipy_distribution_then_it_should_return_correctly_
|
|||
def test_given_gaussian_data_when_fitting_scipy_distribution_automatically_then_it_should_return_correctly_fitted_parameter_values():
|
||||
distribution = ScipyDistribution()
|
||||
|
||||
X = np.random.normal(0, 1, 1000)
|
||||
X = np.random.normal(0, 1, 5000)
|
||||
distribution.fit(X)
|
||||
|
||||
assert np.mean(distribution.draw_samples(1000)) == approx(0, abs=0.1)
|
||||
assert np.std(distribution.draw_samples(1000)) == approx(1, abs=0.1)
|
||||
assert np.mean(distribution.draw_samples(1000)) == approx(0, abs=0.2)
|
||||
assert np.std(distribution.draw_samples(1000)) == approx(1, abs=0.2)
|
||||
|
||||
|
||||
def test_when_drawing_samples_from_empirical_distribution_then_all_samples_should_be_present_in_the_data():
|
||||
|
@ -74,9 +74,9 @@ def test_when_fitting_scipy_distribution_with_normal_distribution_then_it_should
|
|||
@flaky(max_runs=5)
|
||||
def test_when_fitting_scipy_distribution_with_beta_distribution_then_it_should_return_correctly_fitted_parameter_values():
|
||||
distribution = ScipyDistribution(stats.beta)
|
||||
distribution.fit(ScipyDistribution(stats.beta, a=2, b=0.5).draw_samples(10000))
|
||||
distribution.fit(ScipyDistribution(stats.beta, a=2, b=2).draw_samples(10000))
|
||||
|
||||
assert distribution.parameters["loc"] == approx(0, abs=0.1)
|
||||
assert distribution.parameters["scale"] == approx(1, abs=0.1)
|
||||
assert distribution.parameters["a"] == approx(2, abs=0.5)
|
||||
assert distribution.parameters["b"] == approx(0.5, abs=0.5)
|
||||
assert distribution.parameters["b"] == approx(2, abs=0.5)
|
||||
|
|
|
@ -100,7 +100,7 @@ def test_given_categorical_variables_when_draw_interventional_samples_then_retur
|
|||
X1 = np.random.choice(2, 5000).astype(str)
|
||||
|
||||
X2 = []
|
||||
for (x0, x1) in zip(X0, X1):
|
||||
for x0, x1 in zip(X0, X1):
|
||||
if x1 == "0":
|
||||
X2.append(x0 + 2 > 0)
|
||||
else:
|
||||
|
|
Загрузка…
Ссылка в новой задаче