Causality Module
The causality module provides tools for comparing models using causal metrics and tests.
Classes
CausalModels
- class CausalModels(first_model, second_model)
Bases:
objectCausalModels class implementation.
The class is mainly deisgned to implement and include Classification and Regression models of all kinds. The aim is to measure the imapact that one model has on the predictions compared to the second one .
In other words,A/B Testing using causality to measure impact.
- Parameters:
first_model – the first trained model
second_model – the second trained model
- 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 average causal effect of the feature on the residuals.
- Type:
float
Attributes:
individual_causal_effects (np.ndarray): an array of the individual causal effects for the predictionsindividual_causal_effects_resid (np.ndarray): an array of the individual causal effects for the residualsaverage_causal_effect (float): the effect of the feature on the predictions or outcomesaverage_causal_effect_resid (float): the average causal effect of the feature on the residuals
- individual_causal_effects(X)
The individual causal effects of the predicted outcomes.
- Parameters:
X (np.array,pd.DataFrame) – the input values that will be used for prediction.
- Returns:
an array of individual causal effects for the predicted values.
- Return type:
np.ndarray
- individual_causal_effects_resid(X)
The individual causal effects of the residuals. :param X: the input values that will be used for prediction. :type X: np.array,pd.DataFrame
- Returns:
an array of individual causal effects for the predicted probabilites.
- Return type:
np.ndarray
- average_causal_effect(X)
The average difference in the predictions for the two models.
- Parameters:
X (np.array,pd.DataFrame) – the input values that will be used for prediction.
- Returns:
the average causal effect.
- Return type:
float
- average_causal_effect_resid(X)
The average difference in the effects of the residuals.
- Parameters:
X (np.array,pd.DataFrame) – the input values that will be used for prediction.
- Returns:
the average causal effect for the residuals.
- Return type:
float
CausalModelsClassifier
- class CausalModelsClassifier(first_model, second_model)
Bases:
CausalModelsCausalModelClassifier class implementation. The class inherits the CausalModels class
The class is mainly deisgned to implement and include Classification of all kinds. The aim is to measure the imapact that one model has on the predictions compared to the second one .
In other words,A/B Testing using causality to measure impact.
- Parameters:
first_model – the first trained model
second_model – the second trained model
- 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 probabilities
- Type:
np.ndarray
- average_causal_effect
the average causal effect of the first model
- Type:
float
- average_causal_effect_resid
the average causal effect of the first model on the residuals
- Type:
float
- average_causal_effect_probs
the average causal effect of the first model on the predicted probabilities
- Type:
float
Attributes:
individual_causal_effects (np.ndarray): an array of the individual causal effects for the predictionsindividual_causal_effects_resid (np.ndarray): an array of the individual causal effects for the residualsindividual_causal_effects_probs (np.ndarray): an array of the individual causal effects for the probabilitiesaverage_causal_effect (float): the average causal effect of the first modelaverage_causal_effect_resid (float): the average causal effect of the first model on the residualsaverage_causal_effect_probs (float): the average causal effect of the first model on the predicted probabilities
- individual_causal_effects_probs(X)
The individual causal effects of the predicted probabilities
- Parameters:
X (np.array,pd.DataFrame) – the input values that will be used for prediction
- Returns:
an array of individual causal effects for the predicted probabilities
- Return type:
np.ndarray
- average_causal_effect_probs(X)
The average difference in the predicted probabilities for the two models
- Parameters:
X (np.array,pd.DataFrame) – the input values that will be used for prediction
- Returns:
the average causal effect for the predicted probabilities
- Return type:
np.ndarray
CausalModelsRegression
- class CausalModelsRegression(first_model, second_model)
Bases:
CausalModelsCausalModelsRegression class implementation.
The class is mainly deisgned to cover Regression models for tabular data. The aim is to measure the imapact that one model has on the predictions compared to the second one .
In other words,A/B Testing using causality to measure impact
- Parameters:
first_model – the first trained model
second_model – the second trained model
- 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 probabilities
- Type:
np.ndarray
- average_causal_effect
the average causal effect of the first model
- Type:
float
- average_causal_effect_resid
the average causal effect of the first model on the residuals
- Type:
float
- average_causal_effect_probs
the average causal effect of the first model on the predicted probabilities
- Type:
float
Attributes:
individual_causal_effects (np.ndarray): an array of the individual causal effects for the predictionsindividual_causal_effects_resid (np.ndarray): an array of the individual causal effects for the residualsindividual_causal_effects_probs (np.ndarray): an array of the individual causal effects for the probabilitiesaverage_causal_effect (float): the average causal effect of the first modelaverage_causal_effect_resid (float): the average causal effect of the first model on the residualsaverage_causal_effect_probs (float): the average causal effect of the first model on the predicted probabilities