mini_causal.causal_counter.CausalCounterfactualClassifier¶
- class mini_causal.causal_counter.CausalCounterfactualClassifier(model, treatment, control, feature, label)¶
CausalCounterfactualClassifier class implementation. This class is mainly based on the potential outcome framework sometimes referred to as Counterfactual framework in Causal Framework.
The class is mainly deisgned to implement and include Classification models of all kinds. It should be noted that the class inherits all the properties and methods from the CausalCounterfactul class.
The Counterfactual framework assumes two possible outcomes and is based on the what if question.
The class is to measure the impact of features on the model for classification models. With that being said, the treatment set will be the dataset without the feature whereas the control will have the feature we want to measure the impact it has overall.
Hence both the treatment and control models use the same args or parameters for the model. If the model used is a DecisionTreeClassifier for instance then we would have a decision classifier for treatment and as well as for control group.
- Parameters:
model (str) – the model that will be used for the counterfactual workflow.
treatment (pd.DataFrame) – the treatment set.
control (pd.DataFrame) – the control set.
feature (str) – the feature that we want to measure the impact for
label (str) – the name of the target column in the treatment and control. it must be the same and consistent for both sets
- hypotheses¶
return a dictionary with the null and alternative hypotheses
- Type:
Dict[str,str]
- treatment_model¶
the model trained on the treatment set
- Type:
sklearn.base
- control_model¶
the model trained on the control set
- individual_causal_effects¶
an array of the individual causal effects for the predictions
- Type:
np.ndarray
- individual_causal_effects_resid¶
an array of the individual causal effects for the residuals
- Type:
np.ndarray
- individual_causal_effects_probs¶
an array of the individual causal effects for the predicted probabilities
- Type:
np.ndarray
- average_causal_effect¶
the effect of the feature on the predictions or outcomes
- Type:
float
- average_causal_effect_resid¶
the average causal effect of the feature on the residuals
- Type:
float
- average_causal_effect_probs¶
the average causal effect of the feature on the predicted probabilities
- Type:
float
- correlation¶
the correlation between treatment and control predictions
- Type:
float
- correlation_confidence_interval¶
the confidence intervals for the correlation between treatment and control predictions
- Type:
Dict[float,float]
- t_statistic¶
the studentized t-statistic for causal effects
- Type:
float
- pvalue¶
the pvalue for the causal effects
- Type:
float
- causal_effect_stratified¶
the causal effect for strata using rss method for the outcomes or predictions
- Type:
pd.DataFrame
- __init__(model, treatment, control, feature, label)¶
Methods
__init__(model, treatment, control, feature, ...)The average causal effect for the probabilities.
The average causal effect for the probabilities
The average causal effect for the probabilities.
causal_effect_stratified(X, strata_feature)The average causal effect for the predicted per stratum.
Returns :
correlation_confidence_interval([alpha])The correlation confidence interval for the correlation between treatment and control outcomes.
Calculates the individual causal effects.
The individual causal effects of the predicted probabilities by calculating the difference between Yc and Yt of predicted probabilities .
The individual causal effects for the residuals.
Returns :
Attributes
correlation_The correlation between the treatment and control predictions.
p_value_summary_The summary dataframe for the treatment and control predictions.
t_statistic_The average causal effect for the probabilities for the stratum.