Model List

Here, every model currently implemented is listed, alongside it’s methods. If you dont know which model to chose, we have a guide here

class pycausal_explorer.forests._causal_forests.BaseCausalForest(forest_algorithm='extratrees', knn_params=None, random_search_params=None, model_search_params=None)[source]
class pycausal_explorer.forests._causal_forests.CausalForestClassifier(forest_algorithm='extratrees', knn_params=None, random_search_params=None, model_search_params=None)[source]

Implementation of the Causal forests model.

It makes use of decision trees and K nearest neighbors models to find similar data points, and compares their outcome when under treatment and when under control to find the effect of treatment.

forest_algorithmbasestring

Which forest algorithm to use. One of “extratrees”, random_forest” or”xgboost”.

knn_paramsdict

Parameters to train KNeighborsRegressor from sklearn.neighbors https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsRegressor.html

random_search_paramsdict

Randomized Search Parameters to be uses by RandomizedSearchCV from sklearn.model_selection https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.RandomizedSearchCV.html

model_search_params=Nonedict

Model Search Parameters to be uses by RandomizedSearchCV from sklearn.model_selection https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.RandomizedSearchCV.html

fit(X, y, *, treatment)[source]

Fit model with variables X and target y.

X{array-like, sparse matrix} of shape (n_samples, n_features)

Features to control for when estimating causal effect.

yarray-like of shape (n_samples,)

Outcome of samples.

treatmentarray-like of shape (n_samples,)

Binary array. Describes wether or not treatment was applied on a given sample.

selfobject

Fitted model.

predict_ite(X)[source]

Predict the individual treatment effect for the model.

If the model does not have an individual treatment effect, return the average treatment effect with the same shape of X.shape[0]. Parameters ———- X : {array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : ndarray of results

class pycausal_explorer.forests._causal_forests.CausalForestRegressor(forest_algorithm='extratrees', knn_params=None, random_search_params=None, model_search_params=None)[source]

Implementation of the Causal forests model.

It makes use of decision trees and K nearest neighbors models to find similar data points, and compares their outcome when under treatment and when under control to find the effect of treatment.

forest_algorithmbasestring

Which forest algorithm to use. One of “extratrees”, random_forest” or”xgboost”.

knn_paramsdict

Parameters to train KNeighborsRegressor from sklearn.neighbors https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsRegressor.html

random_search_paramsdict

Randomized Search Parameters to be uses by RandomizedSearchCV from sklearn.model_selection https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.RandomizedSearchCV.html

model_search_params=Nonedict

Model Search Parameters to be uses by RandomizedSearchCV from sklearn.model_selection https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.RandomizedSearchCV.html

fit(X, y, *, treatment)[source]

Fit model with variables X and target y.

X{array-like, sparse matrix} of shape (n_samples, n_features)

Features to control for when estimating causal effect.

yarray-like of shape (n_samples,)

Outcome of samples.

treatmentarray-like of shape (n_samples,)

Binary array. Describes wether or not treatment was applied on a given sample.

selfobject

Fitted model.

predict_ite(X)[source]

Predict the individual treatment effect for the model.

If the model does not have an individual treatment effect, return the average treatment effect with the same shape of X.shape[0]. Parameters ———- X : {array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : ndarray of results

class pycausal_explorer.linear._linear_models.CausalLinearRegression[source]

Causal Linear Regressor model.

Estimates causal effect using a Linear Regressor.

fit(X, y, *, treatment)[source]

Fit model with variables X and target y.

X{array-like, sparse matrix} of shape (n_samples, n_features)

Features to control for when estimating causal effect.

yarray-like of shape (n_samples,)

Outcome of samples.

treatmentarray-like of shape (n_samples,)

Binary array. Describes wether or not treatment was applied on a given sample.

selfobject

Fitted model.

predict_ite(X)[source]

Predict the individual treatment effect for the model.

If the model does not have an individual treatment effect, return the average treatment effect with the same shape of X.shape[0]. Parameters ———- X : {array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : ndarray of results

class pycausal_explorer.linear._linear_models.CausalLogisticRegression[source]

Causal Logistic Regressor model.

Estimates causal effect using a Logistic Regressor.

fit(X, y, *, treatment)[source]

Fit model with variables X and target y.

X{array-like, sparse matrix} of shape (n_samples, n_features)

Features to control for when estimating causal effect.

yarray-like of shape (n_samples,)

Outcome of samples.

treatmentarray-like of shape (n_samples,)

Binary array. Describes wether or not treatment was applied on a given sample.

selfobject

Fitted model.

predict_ite(X)[source]

Predict the individual treatment effect for the model.

If the model does not have an individual treatment effect, return the average treatment effect with the same shape of X.shape[0]. Parameters ———- X : {array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : ndarray of results

class pycausal_explorer.meta._single_learner.SingleLearnerBase(learner)[source]
fit(X, y, *, treatment)[source]

Fit model with variables X and target y.

X{array-like, sparse matrix} of shape (n_samples, n_features)

Features to control for when estimating causal effect.

yarray-like of shape (n_samples,)

Outcome of samples.

treatmentarray-like of shape (n_samples,)

Binary array. Describes wether or not treatment was applied on a given sample.

selfobject

Fitted model.

class pycausal_explorer.meta._single_learner.SingleLearnerClassifier(learner)[source]

Implementation of the single learner model.

Logistic version, should be used with binary data.

Uses a single provided model to predict outcome when under treatment, and when not. Uses that to estimate treatment effect.

learner: estimator object

base learner to use when predicting outcome. Should implement fit and predict methods.

predict_ite(X)[source]

Predict the individual treatment effect for the model.

If the model does not have an individual treatment effect, return the average treatment effect with the same shape of X.shape[0]. Parameters ———- X : {array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : ndarray of results

class pycausal_explorer.meta._single_learner.SingleLearnerRegressor(learner)[source]

Implementation of the single learner model.

Regressor version, should be used with continuous data.

Uses a single provided model to predict outcome when under treatment, and when not. Uses that to estimate treatment effect.

learner: estimator object

base learner to use when predicting outcome. Should implement fit and predict methods.

predict_ite(X)[source]

Predict the individual treatment effect for the model.

If the model does not have an individual treatment effect, return the average treatment effect with the same shape of X.shape[0]. Parameters ———- X : {array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : ndarray of results

class pycausal_explorer.meta._tlearner.BaseTLearner(treatment_learner, control_learner)[source]

Implementation of the two learner model, also known as grouped conditional outcome model (GCOM).

Uses a provided model to predict outcome under treatment, and another model when not under treatment. Uses both models to estimate treatment effect.

treatment_learner: estimator object

base learner for samples under treatment.

control_learner: estimator object

base learner for samples not under treatment.

fit(X, y, *, treatment)[source]

Fit model with variables X and target y.

X{array-like, sparse matrix} of shape (n_samples, n_features)

Features to control for when estimating causal effect.

yarray-like of shape (n_samples,)

Outcome of samples.

treatmentarray-like of shape (n_samples,)

Binary array. Describes wether or not treatment was applied on a given sample.

selfobject

Fitted model.

class pycausal_explorer.meta._tlearner.TLearnerLogistic(treatment_learner, control_learner)[source]

Implementation of the two learner model, also known as grouped conditional outcome model (GCOM).

Logistic version. Should be used with binary outcome data.

Uses a provided model to predict probability of outcome under treatment, and another model whe not under treatment. Uses both models to estimate treatment effect.

treatment_learner: estimator object

base learner for samples under treatment.

control_learner: estimator object

base learner for samples not under treatment.

predict_ite(X)[source]

Predict the individual treatment effect for the model.

If the model does not have an individual treatment effect, return the average treatment effect with the same shape of X.shape[0]. Parameters ———- X : {array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : ndarray of results

class pycausal_explorer.meta._tlearner.TLearnerRegressor(treatment_learner, control_learner)[source]

Implementation of the two learner model, also known as grouped conditional outcome model (GCOM).

Regressor version. Should be used with continuous outcome data.

Uses a provided model to predict outcome under treatment, and another model to predict outcome when not under treatment. Uses both models to estimate treatment effect.

treatment_learner: estimator object

base learner for samples under treatment.

control_learner: estimator object

base learner for samples not under treatment.

predict_ite(X)[source]

Predict the individual treatment effect for the model.

If the model does not have an individual treatment effect, return the average treatment effect with the same shape of X.shape[0]. Parameters ———- X : {array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : ndarray of results

class pycausal_explorer.meta._xlearner.XLearner(learner=RandomForestRegressor(), u0=None, u1=None, te_u0=None, te_u1=None, random_state=42)[source]

Implementation of the X-learner.

It consists of estimating heterogeneous treatment effect using four machine learning models. Details of X-learner theory are available at Kunzel et al. (2018) (https://arxiv.org/abs/1706.03461).

learner: base learner to use in all models. Either leaner or (u0, u1, te_u0, te_u1) must be filled u0: model used to estimate outcome in the control group u1: model used to estimate outcome in the treatment group te_u0: model used to estimate treatment effect in the control group te_u1: model used to estimate treatment effect in the treatment group group random_state: random state

fit(X, y, *, treatment)[source]

Fit model with variables X and target y.

X{array-like, sparse matrix} of shape (n_samples, n_features)

Features to control for when estimating causal effect.

yarray-like of shape (n_samples,)

Outcome of samples.

treatmentarray-like of shape (n_samples,)

Binary array. Describes wether or not treatment was applied on a given sample.

selfobject

Fitted model.

predict_ite(X)[source]

Predict the individual treatment effect for the model.

If the model does not have an individual treatment effect, return the average treatment effect with the same shape of X.shape[0]. Parameters ———- X : {array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : ndarray of results

class pycausal_explorer.meta._doubleML.DoubleMLBinaryTreatment(outcome_learner, treatment_learner)[source]

Double Machine Learning model. Estimates causal effect using two different models: one models outcome, and another models treatment.

Binary treatment version. Should be used when treatment is a binary variable.

outcome_learnerestimator object

base learner to use when predicting outcome. Should implement fit and predict methods.

treatment_learnerestimator object

base learner to use when predicting treatment probability. Should be a classifier learner that implements fit and predict_proba methods.

fit(X, y, *, treatment)[source]

Fit model with variables X and target y.

X{array-like, sparse matrix} of shape (n_samples, n_features)

Features to control for when estimating causal effect.

yarray-like of shape (n_samples,)

Outcome of samples.

treatmentarray-like of shape (n_samples,)

Binary array. Describes wether or not treatment was applied on a given sample.

selfobject

Fitted model.

predict_ite(X)[source]

Predict the individual treatment effect for the model.

If the model does not have an individual treatment effect, return the average treatment effect with the same shape of X.shape[0]. Parameters ———- X : {array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : ndarray of results

class pycausal_explorer.meta._doubleML.DoubleMLLinear(outcome_learner, treatment_learner, score='partial-out', k_fold=5)[source]

Double Machine Learning model. Estimates causal effect using two different models: one models outcome, and another models treatment.

Linear version. Should be used when you believe treatment effect is linear, and the treatment variable is continuous

outcome_learnerestimator object

base learner to use when predicting outcome. Should implement fit and predict methods.

treatment_learnerestimator object

base learner to use when predicting treatment. Should implement fit and predict methods.

scorebasestring

Which score function to use. One of “partial-out” and “orthogonal”

fit(X, y, *, treatment)[source]

Fit model with variables X and target y.

X{array-like, sparse matrix} of shape (n_samples, n_features)

Features to control for when estimating causal effect.

yarray-like of shape (n_samples,)

Outcome of samples.

treatmentarray-like of shape (n_samples,)

Binary array. Describes wether or not treatment was applied on a given sample.

selfobject

Fitted model.

predict_ite(X)[source]

Predict the individual treatment effect for the model.

If the model does not have an individual treatment effect, return the average treatment effect with the same shape of X.shape[0]. Parameters ———- X : {array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : ndarray of results

class pycausal_explorer.nearest_neighbors._k_nearest_neighbors.CausalKNNBaseModel(params={'metric': 'euclidean', 'n_neighbors': 10}, scale=True)[source]
fit(X, y, *, treatment)[source]

Fit model with variables X and target y.

X{array-like, sparse matrix} of shape (n_samples, n_features)

Features to control for when estimating causal effect.

yarray-like of shape (n_samples,)

Outcome of samples.

treatmentarray-like of shape (n_samples,)

Binary array. Describes wether or not treatment was applied on a given sample.

selfobject

Fitted model.

predict_ite(X)[source]

Predict the individual treatment effect for the model.

If the model does not have an individual treatment effect, return the average treatment effect with the same shape of X.shape[0]. Parameters ———- X : {array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : ndarray of results

class pycausal_explorer.nearest_neighbors._k_nearest_neighbors.CausalKNNClassifier(*args, **kwargs)[source]
predict_ite(X)[source]

Predict the individual treatment effect for the model.

If the model does not have an individual treatment effect, return the average treatment effect with the same shape of X.shape[0]. Parameters ———- X : {array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : ndarray of results

class pycausal_explorer.nearest_neighbors._k_nearest_neighbors.CausalKNNRegressor(*args, **kwargs)[source]
class pycausal_explorer.reweight._iptw.IPTW(propensity_score=<pycausal_explorer.reweight._propensity_score.PropensityScore object>)[source]

Implements Inverse Probability Treatment Weighting (IPTW) model.

This model weights the units based on the propensity score. It uses all units to get the average treatment effect, so all units receives the same ite. Parameters ———- propensity_score: model used to calculate propensity score.

fit(X, y, *, treatment)[source]

Fit model with variables X and target y.

X{array-like, sparse matrix} of shape (n_samples, n_features)

Features to control for when estimating causal effect.

yarray-like of shape (n_samples,)

Outcome of samples.

treatmentarray-like of shape (n_samples,)

Binary array. Describes wether or not treatment was applied on a given sample.

selfobject

Fitted model.

predict_ate(X)[source]

Predict the average treatment effect for the model.

X{array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : float result

predict_ite(X)[source]

Predict the individual treatment effect for the model.

If the model does not have an individual treatment effect, return the average treatment effect with the same shape of X.shape[0]. Parameters ———- X : {array-like, sparse matrix} of shape (n_samples, n_features)

Features of each sample

treatment_effect : ndarray of results

class pycausal_explorer.reweight._propensity_score.PropensityScore(model=LogisticRegression(), scaler=StandardScaler())[source]

Implements the Propensity Score model.

It fits a model with the target being the treatment, where the output is the probability of the individual being treated.

model: model used to calculate the propensity score scaler: transformation used in the features space