How to use the causalml.inference.meta.BaseXRegressor function in causalml

To help you get started, we’ve selected a few causalml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uber / causalml / tests / test_meta_learners.py View on Github external
def test_BaseXRegressor(generate_regression_data):
    y, X, treatment, tau, b, e = generate_regression_data()

    learner = BaseXRegressor(learner=XGBRegressor())

    # check the accuracy of the ATE estimation
    ate_p, lb, ub = learner.estimate_ate(X=X, p=e, treatment=treatment, y=y)
    assert (ate_p >= lb) and (ate_p <= ub)
    assert ape(tau.mean(), ate_p) < ERROR_THRESHOLD

    # check the accuracy of the CATE estimation with the bootstrap CI
    cate_p, _, _ = learner.fit_predict(X=X, p=e, treatment=treatment, y=y, return_ci=True, n_bootstraps=10)
    assert gini(tau, cate_p.flatten()) > .5
github inovex / justcause / src / justcause / learners / meta / xlearner.py View on Github external
Args:
            learner: default learner for all roles
            outcome_learner_c: specific learner for control outcome function
            outcome_learner_t: specific learner for treated outcome function
            effect_learner_c: specific learner for treated effect
            effect_learner_t: specific learner for control effect
        """
        from causalml.inference.meta import BaseXRegressor

        if (learner is not None) or (
            (outcome_learner_c is not None)
            and (outcome_learner_t is not None)
            and (effect_learner_c is not None)
            and (effect_learner_t is not None)
        ):
            self.model = BaseXRegressor(
                learner,
                outcome_learner_c,
                outcome_learner_t,
                effect_learner_c,
                effect_learner_t,
            )
        else:
            # Assign default learner
            learner = LassoLars()
            self.model = BaseXRegressor(
                learner,
                outcome_learner_c,
                outcome_learner_t,
                effect_learner_c,
                effect_learner_t,
            )
github inovex / justcause / src / justcause / learners / meta / xlearner.py View on Github external
(outcome_learner_c is not None)
            and (outcome_learner_t is not None)
            and (effect_learner_c is not None)
            and (effect_learner_t is not None)
        ):
            self.model = BaseXRegressor(
                learner,
                outcome_learner_c,
                outcome_learner_t,
                effect_learner_c,
                effect_learner_t,
            )
        else:
            # Assign default learner
            learner = LassoLars()
            self.model = BaseXRegressor(
                learner,
                outcome_learner_c,
                outcome_learner_t,
                effect_learner_c,
                effect_learner_t,
            )