Ejemplo n.º 1
0
 def test_param(self):
     """Testing the completion of the fit and effect estimation of an automated Parametric DML"""
     Y, T, X, _ = ihdp_surface_B()
     est = AutomatedLinearDML(model_y=automl_model_reg(),
                              model_t=GradientBoostingClassifier(),
                              featurizer=None,
                              discrete_treatment=True)
     est.fit(Y, T, X=X)
     _ = est.effect(X)
Ejemplo n.º 2
0
    def test_SLearner(self):
        """Testing the completion of the fit and effect estimation of an AutomatedSLearner"""
        # Test constant treatment effect with multi output Y
        # Test heterogeneous treatment effect
        # Need interactions between T and features
        Y, T, X, _ = ihdp_surface_B()
        est = AutomatedSLearner(overall_model=automl_model_reg())

        est.fit(Y, T, X=X)
        _ = est.effect(X)
Ejemplo n.º 3
0
    def test_TLearner(self):
        """Testing the completion of the fit and effect estimation of an AutomatedTLearner"""
        # TLearner test
        # Instantiate TLearner
        Y, T, X, _ = ihdp_surface_B()
        est = AutomatedTLearner(models=automl_model_reg())

        # Test constant and heterogeneous treatment effect, single and multi output y

        est.fit(Y, T, X=X)
        _ = est.effect(X)
Ejemplo n.º 4
0
 def test_nonparam(self):
     """Testing the completion of the fit and effect estimation of an automated Nonparametic DML"""
     Y, T, X, _ = ihdp_surface_B()
     est = AutomatedNonParamDML(
         model_y=automl_model_reg(),
         model_t=automl_model_clf(),
         model_final=automl_model_sample_weight_reg(),
         featurizer=None,
         discrete_treatment=True)
     est.fit(Y, T, X=X)
     _ = est.effect(X)
Ejemplo n.º 5
0
def simulate2(trial, std0=0, std1=0, scenario='A'):    
    rct_res = []
    adpt0_res = []
    adpt1_res = []
    true_res = []
    
    for t in range(trial):
        if scenario == 'A':
            Y, T, X, true_ITE = dgps.ihdp_surface_A()
        elif scenario == 'B':
            Y, T, X, true_ITE = dgps.ihdp_surface_B()
        
        perm = np.random.permutation(len(Y))
        Y = Y[perm]
        T = T[perm]
        X = X[perm]
        
        Y1 = Y.copy()
        Y1[T==0] += true_ITE[T==0]
        Y1 += np.random.normal(0, std1, size=len(Y1))

        Y0 = Y.copy()
        Y0[T==1] -= true_ITE[T==1]
        Y0 += np.random.normal(0, std0, size=len(Y0))

        rct = RCT()
        adpt0 = Adapt(pretraining=10)
        adpt1 = Adapt(pretraining=100)
        opt0 = OPT()
        opt1 = OPT()

        rct_temp = []
        adpt0_temp = []
        adpt1_temp = []
        true_temp = []
        
        for period_t in range(len(Y)):            
            rct(period_t, X[period_t], Y0[period_t], Y1[period_t])
            adpt0(period_t, X[period_t], Y0[period_t], Y1[period_t])
            adpt1(period_t, X[period_t], Y0[period_t], Y1[period_t])
            
            if period_t > 2:
                rct_temp.append(rct.effect())
                adpt0_temp.append(adpt0.effect())
                adpt1_temp.append(adpt1.effect())
                true_temp.append(np.mean(true_ITE))
            
        rct_res.append(rct_temp)
        adpt0_res.append(adpt0_temp)
        adpt1_res.append(adpt1_temp)
        true_res.append(true_temp)

    return rct_res, adpt0_res, adpt1_res, true_res
Ejemplo n.º 6
0
    def test_forest_dml(self):
        """Testing the completion of the fit and effect estimation of an AutomatedForestDML"""

        Y, T, X, _ = ihdp_surface_B()
        est = AutomatedForestDML(model_y=automl_model_reg(),
                                 model_t=GradientBoostingClassifier(),
                                 discrete_treatment=True,
                                 n_estimators=1000,
                                 subsample_fr=.8,
                                 min_samples_leaf=10,
                                 min_impurity_decrease=0.001,
                                 verbose=0,
                                 min_weight_fraction_leaf=.01)
        est.fit(Y, T, X=X)
        _ = est.effect(X)
Ejemplo n.º 7
0
    def automl_model_clf():
        return copy.deepcopy(AUTOML_CONFIG_CLF)

    # Linear models are required for parametric dml

    def automl_model_linear_reg():
        return copy.deepcopy(AUTOML_CONFIG_LINEAR_REG)

    # sample weighting models are required for nonparametric dml

    def automl_model_sample_weight_reg():
        return copy.deepcopy(AUTOML_CONFIG_SAMPLE_WEIGHT_REG)

    # Test values
    Y, T, X, _ = ihdp_surface_B()
except ImportError:
    pass  # automl not installed


@pytest.mark.automl
class TestAutomatedDML(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        subscription_id = os.getenv("SUBSCRIPTION_ID")
        resource_group = os.getenv("RESOURCE_GROUP")
        workspace_name = os.getenv("WORKSPACE_NAME")

        auth = AzureCliAuthentication()

        setAutomatedMLWorkspace(auth=auth,