mini_causal.causal_counter.CausalCounterfactual¶
- class mini_causal.causal_counter.CausalCounterfactual(model, treatment: pandas.DataFrame, control: pandas.DataFrame, feature: str, label: str)¶
CausalCounterfactual class implementation. This class is mainly based on the potential outcome framework sometimes referred to as Counterfactual framework in Causal Framework.
The Counterfactual framework assumes two possible outcomes and is based on the what if question. The workflow used in the class is the t-learner method which takes in two different sets and train two different models.
However the aim in the CausalCounterfactual class is to measure the impact of features on the model. 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
- average_causal_effect¶
the effect of the feature on the predictions or outcomes.
- Type:
float
- average_causal_effect_resid¶
the effect of the feature on the residuals.
- 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 individual causal effects.
- Type:
float
- p_value¶
the pvalue for the outcome individual causal effects.
- Type:
float
- causal_effect_stratified¶
the causal effect per stratum using rss method in a dataframe format
- Type:
pd.DataFrame
- __init__(model, treatment: pandas.DataFrame, control: pandas.DataFrame, feature: str, label: str)¶
Methods
__init__(model, treatment, control, feature, ...)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 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.