How to use the causallib.evaluation.weight_evaluator.WeightEvaluatorPredictions function in causallib

To help you get started, we’ve selected a few causallib 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 IBM / causallib / causallib / evaluation / weight_evaluator.py View on Github external
curve_data[curve_name] = {"first_ret_value": first_ret_folds,
                                      "second_ret_value": second_ret_folds,
                                      "Thresholds": threshold_folds, "area": area_folds}

        # Rename keys (as will be presented as curve labels in legend)
        curve_data["Weights"] = curve_data.pop("unweighted")
        curve_data["Weighted"] = curve_data.pop("weighted")
        return curve_data


# #################### #
# Propensity Evaluator #
# #################### #


class PropensityEvaluatorPredictions(WeightEvaluatorPredictions):
    """Data structure to hold propensity-model predictions"""

    def __init__(self, weight_by_treatment_assignment, weight_for_being_treated, treatment_assignment_pred,
                 propensity, propensity_by_treatment_assignment):
        super(PropensityEvaluatorPredictions, self).__init__(weight_by_treatment_assignment,
                                                             weight_for_being_treated,
                                                             treatment_assignment_pred)
        self.propensity = propensity
        self.propensity_by_treatment_assignment = propensity_by_treatment_assignment


class PropensityEvaluatorPredictions2(WeightEvaluatorPredictions2):
    """Data structure to hold propensity-model predictions"""

    def __init__(self, weight_matrix, propensity_matrix, treatment_assignment, treatment_assignment_prediction=None):
        super(PropensityEvaluatorPredictions2, self).__init__(weight_matrix, treatment_assignment,
github IBM / causallib / causallib / evaluation / weight_evaluator.py View on Github external
Args:
            X (pd.DataFrame): Covariates.
            a (pd.Series): Target variable - treatment assignment

        Returns:
            WeightEvaluatorPredictions
        """
        weight_by_treatment_assignment = self.estimator.compute_weights(X, a, treatment_values=None,
                                                                        use_stabilized=False)
        weight_for_being_treated = self.estimator.compute_weights(X, a, treatment_values=a.max(),
                                                                  use_stabilized=False)
        treatment_assignment_pred = self.estimator.learner.predict(
            X)  # TODO: maybe add predict_label to interface instead
        treatment_assignment_pred = pd.Series(treatment_assignment_pred, index=X.index)

        prediction = WeightEvaluatorPredictions(weight_by_treatment_assignment,
                                                weight_for_being_treated,
                                                treatment_assignment_pred)
        return prediction

causallib

A Python package for flexible and modular causal inference modeling

Apache-2.0
Latest version published 9 months ago

Package Health Score

73 / 100
Full package analysis

Similar packages