# econml._cate_estimator¶

Base classes for all CATE estimators.

Classes

 Base class for all CATE estimators in this package. Mixin for cate models where the final stage is a debiased lasso model. Mixin for cate models where the final stage is a debiased lasso model. Base class for all CATE estimators with linear treatment effects in this package. Base class for models where the final stage is a linear model. Base class for models where the final stage is a linear model. Mixin class that offers inference=’statsmodels’ options to the CATE estimator that inherits it. Mixin class that offers inference=’statsmodels’ options to the CATE estimator that inherits it. Mixin which automatically handles promotions of scalar treatments to the appropriate shape.
class econml._cate_estimator.BaseCateEstimator[source]

Bases: object

Base class for all CATE estimators in this package.

ate(X=None, *, T0, T1)[source]

Calculate the average treatment effect $$E_X[\tau(X, T0, T1)]$$.

The effect is calculated between the two treatment points and is averaged over the population of X variables.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Average treatment effects on each outcome Note that when Y is a vector rather than a 2-dimensional array, the result will be a scalar

Return type

float or (d_y,) array

ate_inference(X=None, *, T0, T1)[source]

Inference results for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

ate_interval(X=None, *, T0, T1, alpha=0.1)[source]

Confidence intervals for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of ate(X, T0, T1), type of ate(X, T0, T1)) )

cate_feature_names(feature_names=None)[source]

Public interface for getting feature names.

To be overriden by estimators that apply transformations the input features.

Parameters

feature_names (list of strings of length X.shape[1] or None) – The names of the input features. If None and X is a dataframe, it defaults to the column names from the dataframe.

Returns

out_feature_names – Returns feature names.

Return type

list of strings or None

cate_output_names(output_names=None)[source]

Public interface for getting output names.

To be overriden by estimators that apply transformations the outputs.

Parameters

output_names (list of strings of length Y.shape[1] or None) – The names of the outcomes. If None and the Y passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

output_names – Returns output names.

Return type

list of strings

cate_treatment_names(treatment_names=None)[source]

Public interface for getting treatment names.

To be overriden by estimators that apply transformations the treatments.

Parameters

treatment_names (list of strings of length T.shape[1] or None) – The names of the treatments. If None and the T passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

treatment_names – Returns treatment names.

Return type

list of strings

abstract effect(X=None, *, T0, T1)[source]

Calculate the heterogeneous treatment effect $$\tau(X, T0, T1)$$.

The effect is calculated between the two treatment points conditional on a vector of features on a set of m test samples $$\{T0_i, T1_i, X_i\}$$.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Heterogeneous treatment effects on each outcome for each sample Note that when Y is a vector rather than a 2-dimensional array, the corresponding singleton dimension will be collapsed (so this method will return a vector)

Return type

(m, d_y) matrix

effect_inference(X=None, *, T0=0, T1=1)[source]

Inference results for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

effect_interval(X=None, *, T0=0, T1=1, alpha=0.1)[source]

Confidence intervals for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of effect(X, T0, T1), type of effect(X, T0, T1)) )

abstract fit(*args, inference=None, **kwargs)[source]

Estimate the counterfactual model from data, i.e. estimates functions $$\tau(X, T0, T1)$$, $$\partial \tau(T, X)$$.

Note that the signature of this method may vary in subclasses (e.g. classes that don’t support instruments will not allow a Z argument)

Parameters
• Y ((n, d_y) matrix or vector of length n) – Outcomes for each sample

• T ((n, d_t) matrix or vector of length n) – Treatments for each sample

• X (optional (n, d_x) matrix) – Features for each sample

• W (optional (n, d_w) matrix) – Controls for each sample

• Z (optional (n, d_z) matrix) – Instruments for each sample

• inference (optional string, Inference instance, or None) – Method for performing inference. All estimators support 'bootstrap' (or an instance of BootstrapInference), some support other methods as well.

Returns

Return type

self

marginal_ate(T, X=None)[source]

Calculate the average marginal effect $$E_{T, X}[\partial\tau(T, X)]$$.

The marginal effect is calculated around a base treatment point and averaged over the population of X.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Average marginal effects on each outcome Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will be a scalar)

Return type

(d_y, d_t) array

marginal_ate_inference(T, X=None)[source]

Inference results for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_ate_interval(T, X=None, *, alpha=0.1)[source]

Confidence intervals for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_ate(T, X), type of marginal_ate(T, X) )

abstract marginal_effect(T, X=None)[source]

Calculate the heterogeneous marginal effect $$\partial\tau(T, X)$$.

The marginal effect is calculated around a base treatment point conditional on a vector of features on a set of m test samples $$\{T_i, X_i\}$$.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Heterogeneous marginal effects on each outcome for each sample Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will also be a vector)

Return type

(m, d_y, d_t) array

marginal_effect_inference(T, X=None)[source]

Inference results for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_effect_interval(T, X=None, *, alpha=0.1)[source]

Confidence intervals for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_effect(T, X), type of marginal_effect(T, X) )

property dowhy

Get an instance of DoWhyWrapper to allow other functionalities from dowhy package. (e.g. causal graph, refutation test, etc.)

Returns

DoWhyWrapper – An instance of DoWhyWrapper

Return type

instance

class econml._cate_estimator.DebiasedLassoCateEstimatorDiscreteMixin[source]

Mixin for cate models where the final stage is a debiased lasso model.

ate(X=None, *, T0, T1)

Calculate the average treatment effect $$E_X[\tau(X, T0, T1)]$$.

The effect is calculated between the two treatment points and is averaged over the population of X variables.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Average treatment effects on each outcome Note that when Y is a vector rather than a 2-dimensional array, the result will be a scalar

Return type

float or (d_y,) array

ate_inference(X=None, *, T0, T1)

Inference results for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

ate_interval(X=None, *, T0, T1, alpha=0.1)

Confidence intervals for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of ate(X, T0, T1), type of ate(X, T0, T1)) )

cate_feature_names(feature_names=None)

Public interface for getting feature names.

To be overriden by estimators that apply transformations the input features.

Parameters

feature_names (list of strings of length X.shape[1] or None) – The names of the input features. If None and X is a dataframe, it defaults to the column names from the dataframe.

Returns

out_feature_names – Returns feature names.

Return type

list of strings or None

cate_output_names(output_names=None)

Public interface for getting output names.

To be overriden by estimators that apply transformations the outputs.

Parameters

output_names (list of strings of length Y.shape[1] or None) – The names of the outcomes. If None and the Y passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

output_names – Returns output names.

Return type

list of strings

cate_treatment_names(treatment_names=None)

Public interface for getting treatment names.

To be overriden by estimators that apply transformations the treatments.

Parameters

treatment_names (list of strings of length T.shape[1] or None) – The names of the treatments. If None and the T passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

treatment_names – Returns treatment names.

Return type

list of strings

coef_(T)

The coefficients in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters

T (alphanumeric) – The input treatment for which we want the coefficients.

Returns

coef – Where n_x is the number of features that enter the final model (either the dimension of X or the dimension of featurizer.fit_transform(X) if the CATE estimator has a featurizer.)

Return type

(n_x,) or (n_y, n_x) array like

coef__inference(T)

The inference for the coefficients in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters

T (alphanumeric) – The input treatment for which we want the coefficients.

Returns

InferenceResults – The inference of the coefficients in the final linear model

Return type

object

coef__interval(T, *, alpha=0.1)

The confidence interval for the coefficients in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters
• T (alphanumeric) – The input treatment for which we want the coefficients.

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and upper bounds of the confidence interval for each quantity.

Return type

tuple(type of coef_(T), type of coef_(T))

abstract effect(X=None, *, T0, T1)

Calculate the heterogeneous treatment effect $$\tau(X, T0, T1)$$.

The effect is calculated between the two treatment points conditional on a vector of features on a set of m test samples $$\{T0_i, T1_i, X_i\}$$.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Heterogeneous treatment effects on each outcome for each sample Note that when Y is a vector rather than a 2-dimensional array, the corresponding singleton dimension will be collapsed (so this method will return a vector)

Return type

(m, d_y) matrix

effect_inference(X=None, *, T0=0, T1=1)

Inference results for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

effect_interval(X=None, *, T0=0, T1=1, alpha=0.1)

Confidence intervals for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of effect(X, T0, T1), type of effect(X, T0, T1)) )

abstract fit(*args, inference=None, **kwargs)

Estimate the counterfactual model from data, i.e. estimates functions $$\tau(X, T0, T1)$$, $$\partial \tau(T, X)$$.

Note that the signature of this method may vary in subclasses (e.g. classes that don’t support instruments will not allow a Z argument)

Parameters
• Y ((n, d_y) matrix or vector of length n) – Outcomes for each sample

• T ((n, d_t) matrix or vector of length n) – Treatments for each sample

• X (optional (n, d_x) matrix) – Features for each sample

• W (optional (n, d_w) matrix) – Controls for each sample

• Z (optional (n, d_z) matrix) – Instruments for each sample

• inference (optional string, Inference instance, or None) – Method for performing inference. All estimators support 'bootstrap' (or an instance of BootstrapInference), some support other methods as well.

Returns

Return type

self

intercept_(T)

The intercept in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters

T (alphanumeric) – The input treatment for which we want the coefficients.

Returns

intercept

Return type

float or (n_y,) array like

intercept__inference(T)

The inference of the intercept in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters

T (alphanumeric) – The input treatment for which we want the coefficients.

Returns

InferenceResults – The inference of the intercept in the final linear model

Return type

object

intercept__interval(T, *, alpha=0.1)

The intercept in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters
• T (alphanumeric) – The input treatment for which we want the coefficients.

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and upper bounds of the confidence interval.

Return type

tuple(type of intercept_(T), type of intercept_(T))

marginal_ate(T, X=None)

Calculate the average marginal effect $$E_{T, X}[\partial\tau(T, X)]$$.

The marginal effect is calculated around a base treatment point and averaged over the population of X.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Average marginal effects on each outcome Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will be a scalar)

Return type

(d_y, d_t) array

marginal_ate_inference(T, X=None)

Inference results for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_ate_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_ate(T, X), type of marginal_ate(T, X) )

abstract marginal_effect(T, X=None)

Calculate the heterogeneous marginal effect $$\partial\tau(T, X)$$.

The marginal effect is calculated around a base treatment point conditional on a vector of features on a set of m test samples $$\{T_i, X_i\}$$.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Heterogeneous marginal effects on each outcome for each sample Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will also be a vector)

Return type

(m, d_y, d_t) array

marginal_effect_inference(T, X=None)

Inference results for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_effect_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_effect(T, X), type of marginal_effect(T, X) )

summary(T, *, alpha=0.1, value=0, decimals=3, feature_names=None, treatment_names=None, output_names=None)

The summary of coefficient and intercept in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters
• alpha (optional float in [0, 1] (default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

• value (optinal float (default=0)) – The mean value of the metric you’d like to test under null hypothesis.

• decimals (optinal int (default=3)) – Number of decimal places to round each column to.

• feature_names (optional list of strings or None (default is None)) – The input of the feature names

• treatment_names (optional list of strings or None (default is None)) – The names of the treatments

• output_names (optional list of strings or None (default is None)) – The names of the outputs

Returns

smry – this holds the summary tables and text, which can be printed or converted to various output formats.

Return type

Summary instance

property dowhy

Get an instance of DoWhyWrapper to allow other functionalities from dowhy package. (e.g. causal graph, refutation test, etc.)

Returns

DoWhyWrapper – An instance of DoWhyWrapper

Return type

instance

class econml._cate_estimator.DebiasedLassoCateEstimatorMixin[source]

Mixin for cate models where the final stage is a debiased lasso model.

ate(X=None, *, T0, T1)

Calculate the average treatment effect $$E_X[\tau(X, T0, T1)]$$.

The effect is calculated between the two treatment points and is averaged over the population of X variables.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Average treatment effects on each outcome Note that when Y is a vector rather than a 2-dimensional array, the result will be a scalar

Return type

float or (d_y,) array

ate_inference(X=None, *, T0, T1)

Inference results for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

ate_interval(X=None, *, T0, T1, alpha=0.1)

Confidence intervals for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of ate(X, T0, T1), type of ate(X, T0, T1)) )

cate_feature_names(feature_names=None)

Public interface for getting feature names.

To be overriden by estimators that apply transformations the input features.

Parameters

feature_names (list of strings of length X.shape[1] or None) – The names of the input features. If None and X is a dataframe, it defaults to the column names from the dataframe.

Returns

out_feature_names – Returns feature names.

Return type

list of strings or None

cate_output_names(output_names=None)

Public interface for getting output names.

To be overriden by estimators that apply transformations the outputs.

Parameters

output_names (list of strings of length Y.shape[1] or None) – The names of the outcomes. If None and the Y passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

output_names – Returns output names.

Return type

list of strings

cate_treatment_names(treatment_names=None)

Public interface for getting treatment names.

To be overriden by estimators that apply transformations the treatments.

Parameters

treatment_names (list of strings of length T.shape[1] or None) – The names of the treatments. If None and the T passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

treatment_names – Returns treatment names.

Return type

list of strings

coef__inference()

The inference of coefficients in the linear model of the constant marginal treatment effect.

Returns

InferenceResults – The inference of the coefficients in the final linear model

Return type

object

coef__interval(*, alpha=0.1)

The coefficients in the linear model of the constant marginal treatment effect.

Parameters

alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lb, ub – The lower and upper bounds of the confidence interval for each quantity.

Return type

tuple(type of coef_(), type of coef_())

abstract effect(X=None, *, T0, T1)

Calculate the heterogeneous treatment effect $$\tau(X, T0, T1)$$.

The effect is calculated between the two treatment points conditional on a vector of features on a set of m test samples $$\{T0_i, T1_i, X_i\}$$.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Heterogeneous treatment effects on each outcome for each sample Note that when Y is a vector rather than a 2-dimensional array, the corresponding singleton dimension will be collapsed (so this method will return a vector)

Return type

(m, d_y) matrix

effect_inference(X=None, *, T0=0, T1=1)

Inference results for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

effect_interval(X=None, *, T0=0, T1=1, alpha=0.1)

Confidence intervals for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of effect(X, T0, T1), type of effect(X, T0, T1)) )

abstract fit(*args, inference=None, **kwargs)

Estimate the counterfactual model from data, i.e. estimates functions $$\tau(X, T0, T1)$$, $$\partial \tau(T, X)$$.

Note that the signature of this method may vary in subclasses (e.g. classes that don’t support instruments will not allow a Z argument)

Parameters
• Y ((n, d_y) matrix or vector of length n) – Outcomes for each sample

• T ((n, d_t) matrix or vector of length n) – Treatments for each sample

• X (optional (n, d_x) matrix) – Features for each sample

• W (optional (n, d_w) matrix) – Controls for each sample

• Z (optional (n, d_z) matrix) – Instruments for each sample

• inference (optional string, Inference instance, or None) – Method for performing inference. All estimators support 'bootstrap' (or an instance of BootstrapInference), some support other methods as well.

Returns

Return type

self

intercept__inference()

The inference of intercept in the linear model of the constant marginal treatment effect.

Returns

InferenceResults – The inference of the intercept in the final linear model

Return type

object

intercept__interval(*, alpha=0.1)

The intercept in the linear model of the constant marginal treatment effect.

Parameters

alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and upper bounds of the confidence interval.

Return type

tuple(type of intercept_(), type of intercept_())

marginal_ate(T, X=None)

Calculate the average marginal effect $$E_{T, X}[\partial\tau(T, X)]$$.

The marginal effect is calculated around a base treatment point and averaged over the population of X.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Average marginal effects on each outcome Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will be a scalar)

Return type

(d_y, d_t) array

marginal_ate_inference(T, X=None)

Inference results for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_ate_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_ate(T, X), type of marginal_ate(T, X) )

abstract marginal_effect(T, X=None)

Calculate the heterogeneous marginal effect $$\partial\tau(T, X)$$.

The marginal effect is calculated around a base treatment point conditional on a vector of features on a set of m test samples $$\{T_i, X_i\}$$.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Heterogeneous marginal effects on each outcome for each sample Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will also be a vector)

Return type

(m, d_y, d_t) array

marginal_effect_inference(T, X=None)

Inference results for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_effect_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_effect(T, X), type of marginal_effect(T, X) )

shap_values(X, *, feature_names=None, treatment_names=None, output_names=None, background_samples=100)

Shap value for the final stage models (const_marginal_effect)

Parameters
• X ((m, d_x) matrix) – Features for each sample. Should be in the same shape of fitted X in final stage.

• feature_names (optional None or list of strings of length X.shape[1] (Default=None)) – The names of input features.

• treatment_names (optional None or list (Default=None)) – The name of treatment. In discrete treatment scenario, the name should not include the name of the baseline treatment (i.e. the control treatment, which by default is the alphabetically smaller)

• output_names (optional None or list (Default=None)) – The name of the outcome.

• background_samples (int or None, (Default=100)) – How many samples to use to compute the baseline effect. If None then all samples are used.

Returns

shap_outs – A nested dictionary by using each output name (e.g. ‘Y0’, ‘Y1’, … when output_names=None) and each treatment name (e.g. ‘T0’, ‘T1’, … when treatment_names=None) as key and the shap_values explanation object as value. If the input data at fit time also contain metadata, (e.g. are pandas DataFrames), then the column metatdata for the treatments, outcomes and features are used instead of the above defaults (unless the user overrides with explicitly passing the corresponding names).

Return type

nested dictionary of Explanation object

summary(alpha=0.1, value=0, decimals=3, feature_names=None, treatment_names=None, output_names=None)

The summary of coefficient and intercept in the linear model of the constant marginal treatment effect.

Parameters
• alpha (optional float in [0, 1] (default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

• value (optinal float (default=0)) – The mean value of the metric you’d like to test under null hypothesis.

• decimals (optinal int (default=3)) – Number of decimal places to round each column to.

• feature_names (optional list of strings or None (default is None)) – The input of the feature names

• treatment_names (optional list of strings or None (default is None)) – The names of the treatments

• output_names (optional list of strings or None (default is None)) – The names of the outputs

Returns

smry – this holds the summary tables and text, which can be printed or converted to various output formats.

Return type

Summary instance

property coef_

The coefficients in the linear model of the constant marginal treatment effect.

Returns

coef – Where n_x is the number of features that enter the final model (either the dimension of X or the dimension of featurizer.fit_transform(X) if the CATE estimator has a featurizer.), n_t is the number of treatments, n_y is the number of outcomes. Dimensions are omitted if the original input was a vector and not a 2D array. For binary treatment the n_t dimension is also omitted.

Return type

(n_x,) or (n_t, n_x) or (n_y, n_t, n_x) array like

property dowhy

Get an instance of DoWhyWrapper to allow other functionalities from dowhy package. (e.g. causal graph, refutation test, etc.)

Returns

DoWhyWrapper – An instance of DoWhyWrapper

Return type

instance

property intercept_

The intercept in the linear model of the constant marginal treatment effect.

Returns

intercept – Where n_t is the number of treatments, n_y is the number of outcomes. Dimensions are omitted if the original input was a vector and not a 2D array. For binary treatment the n_t dimension is also omitted.

Return type

float or (n_y,) or (n_y, n_t) array like

class econml._cate_estimator.ForestModelFinalCateEstimatorDiscreteMixin[source]
ate(X=None, *, T0, T1)

Calculate the average treatment effect $$E_X[\tau(X, T0, T1)]$$.

The effect is calculated between the two treatment points and is averaged over the population of X variables.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Average treatment effects on each outcome Note that when Y is a vector rather than a 2-dimensional array, the result will be a scalar

Return type

float or (d_y,) array

ate_inference(X=None, *, T0, T1)

Inference results for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

ate_interval(X=None, *, T0, T1, alpha=0.1)

Confidence intervals for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of ate(X, T0, T1), type of ate(X, T0, T1)) )

cate_feature_names(feature_names=None)

Public interface for getting feature names.

To be overriden by estimators that apply transformations the input features.

Parameters

feature_names (list of strings of length X.shape[1] or None) – The names of the input features. If None and X is a dataframe, it defaults to the column names from the dataframe.

Returns

out_feature_names – Returns feature names.

Return type

list of strings or None

cate_output_names(output_names=None)

Public interface for getting output names.

To be overriden by estimators that apply transformations the outputs.

Parameters

output_names (list of strings of length Y.shape[1] or None) – The names of the outcomes. If None and the Y passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

output_names – Returns output names.

Return type

list of strings

cate_treatment_names(treatment_names=None)

Public interface for getting treatment names.

To be overriden by estimators that apply transformations the treatments.

Parameters

treatment_names (list of strings of length T.shape[1] or None) – The names of the treatments. If None and the T passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

treatment_names – Returns treatment names.

Return type

list of strings

abstract effect(X=None, *, T0, T1)

Calculate the heterogeneous treatment effect $$\tau(X, T0, T1)$$.

The effect is calculated between the two treatment points conditional on a vector of features on a set of m test samples $$\{T0_i, T1_i, X_i\}$$.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Heterogeneous treatment effects on each outcome for each sample Note that when Y is a vector rather than a 2-dimensional array, the corresponding singleton dimension will be collapsed (so this method will return a vector)

Return type

(m, d_y) matrix

effect_inference(X=None, *, T0=0, T1=1)

Inference results for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

effect_interval(X=None, *, T0=0, T1=1, alpha=0.1)

Confidence intervals for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of effect(X, T0, T1), type of effect(X, T0, T1)) )

abstract fit(*args, inference=None, **kwargs)

Estimate the counterfactual model from data, i.e. estimates functions $$\tau(X, T0, T1)$$, $$\partial \tau(T, X)$$.

Note that the signature of this method may vary in subclasses (e.g. classes that don’t support instruments will not allow a Z argument)

Parameters
• Y ((n, d_y) matrix or vector of length n) – Outcomes for each sample

• T ((n, d_t) matrix or vector of length n) – Treatments for each sample

• X (optional (n, d_x) matrix) – Features for each sample

• W (optional (n, d_w) matrix) – Controls for each sample

• Z (optional (n, d_z) matrix) – Instruments for each sample

• inference (optional string, Inference instance, or None) – Method for performing inference. All estimators support 'bootstrap' (or an instance of BootstrapInference), some support other methods as well.

Returns

Return type

self

marginal_ate(T, X=None)

Calculate the average marginal effect $$E_{T, X}[\partial\tau(T, X)]$$.

The marginal effect is calculated around a base treatment point and averaged over the population of X.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Average marginal effects on each outcome Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will be a scalar)

Return type

(d_y, d_t) array

marginal_ate_inference(T, X=None)

Inference results for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_ate_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_ate(T, X), type of marginal_ate(T, X) )

abstract marginal_effect(T, X=None)

Calculate the heterogeneous marginal effect $$\partial\tau(T, X)$$.

The marginal effect is calculated around a base treatment point conditional on a vector of features on a set of m test samples $$\{T_i, X_i\}$$.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Heterogeneous marginal effects on each outcome for each sample Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will also be a vector)

Return type

(m, d_y, d_t) array

marginal_effect_inference(T, X=None)

Inference results for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_effect_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_effect(T, X), type of marginal_effect(T, X) )

property dowhy

Get an instance of DoWhyWrapper to allow other functionalities from dowhy package. (e.g. causal graph, refutation test, etc.)

Returns

DoWhyWrapper – An instance of DoWhyWrapper

Return type

instance

class econml._cate_estimator.ForestModelFinalCateEstimatorMixin[source]
ate(X=None, *, T0, T1)

Calculate the average treatment effect $$E_X[\tau(X, T0, T1)]$$.

The effect is calculated between the two treatment points and is averaged over the population of X variables.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Average treatment effects on each outcome Note that when Y is a vector rather than a 2-dimensional array, the result will be a scalar

Return type

float or (d_y,) array

ate_inference(X=None, *, T0, T1)

Inference results for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

ate_interval(X=None, *, T0, T1, alpha=0.1)

Confidence intervals for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of ate(X, T0, T1), type of ate(X, T0, T1)) )

cate_feature_names(feature_names=None)

Public interface for getting feature names.

To be overriden by estimators that apply transformations the input features.

Parameters

feature_names (list of strings of length X.shape[1] or None) – The names of the input features. If None and X is a dataframe, it defaults to the column names from the dataframe.

Returns

out_feature_names – Returns feature names.

Return type

list of strings or None

cate_output_names(output_names=None)

Public interface for getting output names.

To be overriden by estimators that apply transformations the outputs.

Parameters

output_names (list of strings of length Y.shape[1] or None) – The names of the outcomes. If None and the Y passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

output_names – Returns output names.

Return type

list of strings

cate_treatment_names(treatment_names=None)

Public interface for getting treatment names.

To be overriden by estimators that apply transformations the treatments.

Parameters

treatment_names (list of strings of length T.shape[1] or None) – The names of the treatments. If None and the T passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

treatment_names – Returns treatment names.

Return type

list of strings

abstract effect(X=None, *, T0, T1)

Calculate the heterogeneous treatment effect $$\tau(X, T0, T1)$$.

The effect is calculated between the two treatment points conditional on a vector of features on a set of m test samples $$\{T0_i, T1_i, X_i\}$$.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Heterogeneous treatment effects on each outcome for each sample Note that when Y is a vector rather than a 2-dimensional array, the corresponding singleton dimension will be collapsed (so this method will return a vector)

Return type

(m, d_y) matrix

effect_inference(X=None, *, T0=0, T1=1)

Inference results for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

effect_interval(X=None, *, T0=0, T1=1, alpha=0.1)

Confidence intervals for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of effect(X, T0, T1), type of effect(X, T0, T1)) )

abstract fit(*args, inference=None, **kwargs)

Estimate the counterfactual model from data, i.e. estimates functions $$\tau(X, T0, T1)$$, $$\partial \tau(T, X)$$.

Note that the signature of this method may vary in subclasses (e.g. classes that don’t support instruments will not allow a Z argument)

Parameters
• Y ((n, d_y) matrix or vector of length n) – Outcomes for each sample

• T ((n, d_t) matrix or vector of length n) – Treatments for each sample

• X (optional (n, d_x) matrix) – Features for each sample

• W (optional (n, d_w) matrix) – Controls for each sample

• Z (optional (n, d_z) matrix) – Instruments for each sample

• inference (optional string, Inference instance, or None) – Method for performing inference. All estimators support 'bootstrap' (or an instance of BootstrapInference), some support other methods as well.

Returns

Return type

self

marginal_ate(T, X=None)

Calculate the average marginal effect $$E_{T, X}[\partial\tau(T, X)]$$.

The marginal effect is calculated around a base treatment point and averaged over the population of X.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Average marginal effects on each outcome Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will be a scalar)

Return type

(d_y, d_t) array

marginal_ate_inference(T, X=None)

Inference results for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_ate_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_ate(T, X), type of marginal_ate(T, X) )

abstract marginal_effect(T, X=None)

Calculate the heterogeneous marginal effect $$\partial\tau(T, X)$$.

The marginal effect is calculated around a base treatment point conditional on a vector of features on a set of m test samples $$\{T_i, X_i\}$$.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Heterogeneous marginal effects on each outcome for each sample Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will also be a vector)

Return type

(m, d_y, d_t) array

marginal_effect_inference(T, X=None)

Inference results for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_effect_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_effect(T, X), type of marginal_effect(T, X) )

property dowhy

Get an instance of DoWhyWrapper to allow other functionalities from dowhy package. (e.g. causal graph, refutation test, etc.)

Returns

DoWhyWrapper – An instance of DoWhyWrapper

Return type

instance

class econml._cate_estimator.LinearCateEstimator[source]

Base class for all CATE estimators with linear treatment effects in this package.

ate(X=None, *, T0, T1)

Calculate the average treatment effect $$E_X[\tau(X, T0, T1)]$$.

The effect is calculated between the two treatment points and is averaged over the population of X variables.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Average treatment effects on each outcome Note that when Y is a vector rather than a 2-dimensional array, the result will be a scalar

Return type

float or (d_y,) array

ate_inference(X=None, *, T0, T1)

Inference results for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

ate_interval(X=None, *, T0, T1, alpha=0.1)

Confidence intervals for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of ate(X, T0, T1), type of ate(X, T0, T1)) )

cate_feature_names(feature_names=None)

Public interface for getting feature names.

To be overriden by estimators that apply transformations the input features.

Parameters

feature_names (list of strings of length X.shape[1] or None) – The names of the input features. If None and X is a dataframe, it defaults to the column names from the dataframe.

Returns

out_feature_names – Returns feature names.

Return type

list of strings or None

cate_output_names(output_names=None)

Public interface for getting output names.

To be overriden by estimators that apply transformations the outputs.

Parameters

output_names (list of strings of length Y.shape[1] or None) – The names of the outcomes. If None and the Y passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

output_names – Returns output names.

Return type

list of strings

cate_treatment_names(treatment_names=None)

Public interface for getting treatment names.

To be overriden by estimators that apply transformations the treatments.

Parameters

treatment_names (list of strings of length T.shape[1] or None) – The names of the treatments. If None and the T passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

treatment_names – Returns treatment names.

Return type

list of strings

const_marginal_ate(X=None)[source]

Calculate the average constant marginal CATE $$E_X[\theta(X)]$$.

Parameters

X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample.

Returns

theta – Average constant marginal CATE of each treatment on each outcome. Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will be a scalar)

Return type

(d_y, d_t) matrix

const_marginal_ate_inference(X=None)[source]

Inference results for the quantities $$E_X[\theta(X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters

X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

const_marginal_ate_interval(X=None, *, alpha=0.1)[source]

Confidence intervals for the quantities $$E_X[\theta(X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of const_marginal_ate(X) , type of const_marginal_ate(X) )

abstract const_marginal_effect(X=None)[source]

Calculate the constant marginal CATE $$\theta(·)$$.

The marginal effect is conditional on a vector of features on a set of m test samples X[i].

Parameters

X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample.

Returns

theta – Constant marginal CATE of each treatment on each outcome for each sample X[i]. Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will also be a vector)

Return type

(m, d_y, d_t) matrix or (d_y, d_t) matrix if X is None

const_marginal_effect_inference(X=None)[source]

Inference results for the quantities $$\theta(X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters

X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

const_marginal_effect_interval(X=None, *, alpha=0.1)[source]

Confidence intervals for the quantities $$\theta(X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of const_marginal_effect(X) , type of const_marginal_effect(X) )

effect(X=None, *, T0, T1)[source]

Calculate the heterogeneous treatment effect $$\tau(X, T0, T1)$$.

The effect is calculatred between the two treatment points conditional on a vector of features on a set of m test samples $$\{T0_i, T1_i, X_i\}$$. Since this class assumes a linear effect, only the difference between T0ᵢ and T1ᵢ matters for this computation.

Parameters
• T0 ((m, d_t) matrix) – Base treatments for each sample

• T1 ((m, d_t) matrix) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

effect – Heterogeneous treatment effects on each outcome for each sample. Note that when Y is a vector rather than a 2-dimensional array, the corresponding singleton dimension will be collapsed (so this method will return a vector)

Return type

(m, d_y) matrix (or length m vector if Y was a vector)

effect_inference(X=None, *, T0=0, T1=1)

Inference results for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

effect_interval(X=None, *, T0=0, T1=1, alpha=0.1)

Confidence intervals for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of effect(X, T0, T1), type of effect(X, T0, T1)) )

abstract fit(*args, inference=None, **kwargs)

Estimate the counterfactual model from data, i.e. estimates functions $$\tau(X, T0, T1)$$, $$\partial \tau(T, X)$$.

Note that the signature of this method may vary in subclasses (e.g. classes that don’t support instruments will not allow a Z argument)

Parameters
• Y ((n, d_y) matrix or vector of length n) – Outcomes for each sample

• T ((n, d_t) matrix or vector of length n) – Treatments for each sample

• X (optional (n, d_x) matrix) – Features for each sample

• W (optional (n, d_w) matrix) – Controls for each sample

• Z (optional (n, d_z) matrix) – Instruments for each sample

• inference (optional string, Inference instance, or None) – Method for performing inference. All estimators support 'bootstrap' (or an instance of BootstrapInference), some support other methods as well.

Returns

Return type

self

marginal_ate(T, X=None)[source]

Calculate the average marginal effect $$E_{T, X}[\partial\tau(T, X)]$$.

The marginal effect is calculated around a base treatment point and averaged over the population of X.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Average marginal effects on each outcome Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will be a scalar)

Return type

(d_y, d_t) array

marginal_ate_inference(T, X=None)[source]

Inference results for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_ate_interval(T, X=None, *, alpha=0.1)[source]

Confidence intervals for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_ate(T, X), type of marginal_ate(T, X) )

marginal_effect(T, X=None)[source]

Calculate the heterogeneous marginal effect $$\partial\tau(T, X)$$.

The marginal effect is calculated around a base treatment point conditional on a vector of features on a set of m test samples $$\{T_i, X_i\}$$. Since this class assumes a linear model, the base treatment is ignored in this calculation.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Heterogeneous marginal effects on each outcome for each sample Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will also be a vector)

Return type

(m, d_y, d_t) array

marginal_effect_inference(T, X=None)[source]

Inference results for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_effect_interval(T, X=None, *, alpha=0.1)[source]

Confidence intervals for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_effect(T, X), type of marginal_effect(T, X) )

shap_values(X, *, feature_names=None, treatment_names=None, output_names=None, background_samples=100)[source]

Shap value for the final stage models (const_marginal_effect)

Parameters
• X ((m, d_x) matrix) – Features for each sample. Should be in the same shape of fitted X in final stage.

• feature_names (optional None or list of strings of length X.shape[1] (Default=None)) – The names of input features.

• treatment_names (optional None or list (Default=None)) – The name of treatment. In discrete treatment scenario, the name should not include the name of the baseline treatment (i.e. the control treatment, which by default is the alphabetically smaller)

• output_names (optional None or list (Default=None)) – The name of the outcome.

• background_samples (int or None, (Default=100)) – How many samples to use to compute the baseline effect. If None then all samples are used.

Returns

shap_outs – A nested dictionary by using each output name (e.g. ‘Y0’, ‘Y1’, … when output_names=None) and each treatment name (e.g. ‘T0’, ‘T1’, … when treatment_names=None) as key and the shap_values explanation object as value. If the input data at fit time also contain metadata, (e.g. are pandas DataFrames), then the column metatdata for the treatments, outcomes and features are used instead of the above defaults (unless the user overrides with explicitly passing the corresponding names).

Return type

nested dictionary of Explanation object

property dowhy

Get an instance of DoWhyWrapper to allow other functionalities from dowhy package. (e.g. causal graph, refutation test, etc.)

Returns

DoWhyWrapper – An instance of DoWhyWrapper

Return type

instance

class econml._cate_estimator.LinearModelFinalCateEstimatorDiscreteMixin[source]

Base class for models where the final stage is a linear model.

Subclasses must expose a fitted_models_final attribute returning an array of the fitted models for each non-control treatment

ate(X=None, *, T0, T1)

Calculate the average treatment effect $$E_X[\tau(X, T0, T1)]$$.

The effect is calculated between the two treatment points and is averaged over the population of X variables.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Average treatment effects on each outcome Note that when Y is a vector rather than a 2-dimensional array, the result will be a scalar

Return type

float or (d_y,) array

ate_inference(X=None, *, T0, T1)

Inference results for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

ate_interval(X=None, *, T0, T1, alpha=0.1)

Confidence intervals for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of ate(X, T0, T1), type of ate(X, T0, T1)) )

cate_feature_names(feature_names=None)

Public interface for getting feature names.

To be overriden by estimators that apply transformations the input features.

Parameters

feature_names (list of strings of length X.shape[1] or None) – The names of the input features. If None and X is a dataframe, it defaults to the column names from the dataframe.

Returns

out_feature_names – Returns feature names.

Return type

list of strings or None

cate_output_names(output_names=None)

Public interface for getting output names.

To be overriden by estimators that apply transformations the outputs.

Parameters

output_names (list of strings of length Y.shape[1] or None) – The names of the outcomes. If None and the Y passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

output_names – Returns output names.

Return type

list of strings

cate_treatment_names(treatment_names=None)

Public interface for getting treatment names.

To be overriden by estimators that apply transformations the treatments.

Parameters

treatment_names (list of strings of length T.shape[1] or None) – The names of the treatments. If None and the T passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

treatment_names – Returns treatment names.

Return type

list of strings

coef_(T)[source]

The coefficients in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters

T (alphanumeric) – The input treatment for which we want the coefficients.

Returns

coef – Where n_x is the number of features that enter the final model (either the dimension of X or the dimension of featurizer.fit_transform(X) if the CATE estimator has a featurizer.)

Return type

(n_x,) or (n_y, n_x) array like

coef__inference(T)[source]

The inference for the coefficients in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters

T (alphanumeric) – The input treatment for which we want the coefficients.

Returns

InferenceResults – The inference of the coefficients in the final linear model

Return type

object

coef__interval(T, *, alpha=0.1)[source]

The confidence interval for the coefficients in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters
• T (alphanumeric) – The input treatment for which we want the coefficients.

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and upper bounds of the confidence interval for each quantity.

Return type

tuple(type of coef_(T), type of coef_(T))

abstract effect(X=None, *, T0, T1)

Calculate the heterogeneous treatment effect $$\tau(X, T0, T1)$$.

The effect is calculated between the two treatment points conditional on a vector of features on a set of m test samples $$\{T0_i, T1_i, X_i\}$$.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Heterogeneous treatment effects on each outcome for each sample Note that when Y is a vector rather than a 2-dimensional array, the corresponding singleton dimension will be collapsed (so this method will return a vector)

Return type

(m, d_y) matrix

effect_inference(X=None, *, T0=0, T1=1)

Inference results for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

effect_interval(X=None, *, T0=0, T1=1, alpha=0.1)

Confidence intervals for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of effect(X, T0, T1), type of effect(X, T0, T1)) )

abstract fit(*args, inference=None, **kwargs)

Estimate the counterfactual model from data, i.e. estimates functions $$\tau(X, T0, T1)$$, $$\partial \tau(T, X)$$.

Note that the signature of this method may vary in subclasses (e.g. classes that don’t support instruments will not allow a Z argument)

Parameters
• Y ((n, d_y) matrix or vector of length n) – Outcomes for each sample

• T ((n, d_t) matrix or vector of length n) – Treatments for each sample

• X (optional (n, d_x) matrix) – Features for each sample

• W (optional (n, d_w) matrix) – Controls for each sample

• Z (optional (n, d_z) matrix) – Instruments for each sample

• inference (optional string, Inference instance, or None) – Method for performing inference. All estimators support 'bootstrap' (or an instance of BootstrapInference), some support other methods as well.

Returns

Return type

self

intercept_(T)[source]

The intercept in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters

T (alphanumeric) – The input treatment for which we want the coefficients.

Returns

intercept

Return type

float or (n_y,) array like

intercept__inference(T)[source]

The inference of the intercept in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters

T (alphanumeric) – The input treatment for which we want the coefficients.

Returns

InferenceResults – The inference of the intercept in the final linear model

Return type

object

intercept__interval(T, *, alpha=0.1)[source]

The intercept in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters
• T (alphanumeric) – The input treatment for which we want the coefficients.

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and upper bounds of the confidence interval.

Return type

tuple(type of intercept_(T), type of intercept_(T))

marginal_ate(T, X=None)

Calculate the average marginal effect $$E_{T, X}[\partial\tau(T, X)]$$.

The marginal effect is calculated around a base treatment point and averaged over the population of X.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Average marginal effects on each outcome Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will be a scalar)

Return type

(d_y, d_t) array

marginal_ate_inference(T, X=None)

Inference results for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_ate_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_ate(T, X), type of marginal_ate(T, X) )

abstract marginal_effect(T, X=None)

Calculate the heterogeneous marginal effect $$\partial\tau(T, X)$$.

The marginal effect is calculated around a base treatment point conditional on a vector of features on a set of m test samples $$\{T_i, X_i\}$$.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Heterogeneous marginal effects on each outcome for each sample Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will also be a vector)

Return type

(m, d_y, d_t) array

marginal_effect_inference(T, X=None)

Inference results for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_effect_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_effect(T, X), type of marginal_effect(T, X) )

summary(T, *, alpha=0.1, value=0, decimals=3, feature_names=None, treatment_names=None, output_names=None)[source]

The summary of coefficient and intercept in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters
• alpha (optional float in [0, 1] (default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

• value (optinal float (default=0)) – The mean value of the metric you’d like to test under null hypothesis.

• decimals (optinal int (default=3)) – Number of decimal places to round each column to.

• feature_names (optional list of strings or None (default is None)) – The input of the feature names

• treatment_names (optional list of strings or None (default is None)) – The names of the treatments

• output_names (optional list of strings or None (default is None)) – The names of the outputs

Returns

smry – this holds the summary tables and text, which can be printed or converted to various output formats.

Return type

Summary instance

property dowhy

Get an instance of DoWhyWrapper to allow other functionalities from dowhy package. (e.g. causal graph, refutation test, etc.)

Returns

DoWhyWrapper – An instance of DoWhyWrapper

Return type

instance

class econml._cate_estimator.LinearModelFinalCateEstimatorMixin[source]

Base class for models where the final stage is a linear model.

Such an estimator must implement a model_final_ attribute that points to the fitted final StatsModelsLinearRegression object that represents the fitted CATE model. Also must implement featurizer_ that points to the fitted featurizer and bias_part_of_coef that designates if the intercept is the first element of the model_final_ coefficient.

bias_part_of_coef

Whether the CATE model’s intercept is contained in the final model’s coef_ rather than as a separate intercept_

Type

bool

ate(X=None, *, T0, T1)

Calculate the average treatment effect $$E_X[\tau(X, T0, T1)]$$.

The effect is calculated between the two treatment points and is averaged over the population of X variables.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Average treatment effects on each outcome Note that when Y is a vector rather than a 2-dimensional array, the result will be a scalar

Return type

float or (d_y,) array

ate_inference(X=None, *, T0, T1)

Inference results for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

ate_interval(X=None, *, T0, T1, alpha=0.1)

Confidence intervals for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of ate(X, T0, T1), type of ate(X, T0, T1)) )

cate_feature_names(feature_names=None)

Public interface for getting feature names.

To be overriden by estimators that apply transformations the input features.

Parameters

feature_names (list of strings of length X.shape[1] or None) – The names of the input features. If None and X is a dataframe, it defaults to the column names from the dataframe.

Returns

out_feature_names – Returns feature names.

Return type

list of strings or None

cate_output_names(output_names=None)

Public interface for getting output names.

To be overriden by estimators that apply transformations the outputs.

Parameters

output_names (list of strings of length Y.shape[1] or None) – The names of the outcomes. If None and the Y passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

output_names – Returns output names.

Return type

list of strings

cate_treatment_names(treatment_names=None)

Public interface for getting treatment names.

To be overriden by estimators that apply transformations the treatments.

Parameters

treatment_names (list of strings of length T.shape[1] or None) – The names of the treatments. If None and the T passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

treatment_names – Returns treatment names.

Return type

list of strings

coef__inference()[source]

The inference of coefficients in the linear model of the constant marginal treatment effect.

Returns

InferenceResults – The inference of the coefficients in the final linear model

Return type

object

coef__interval(*, alpha=0.1)[source]

The coefficients in the linear model of the constant marginal treatment effect.

Parameters

alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lb, ub – The lower and upper bounds of the confidence interval for each quantity.

Return type

tuple(type of coef_(), type of coef_())

abstract effect(X=None, *, T0, T1)

Calculate the heterogeneous treatment effect $$\tau(X, T0, T1)$$.

The effect is calculated between the two treatment points conditional on a vector of features on a set of m test samples $$\{T0_i, T1_i, X_i\}$$.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Heterogeneous treatment effects on each outcome for each sample Note that when Y is a vector rather than a 2-dimensional array, the corresponding singleton dimension will be collapsed (so this method will return a vector)

Return type

(m, d_y) matrix

effect_inference(X=None, *, T0=0, T1=1)

Inference results for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

effect_interval(X=None, *, T0=0, T1=1, alpha=0.1)

Confidence intervals for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of effect(X, T0, T1), type of effect(X, T0, T1)) )

abstract fit(*args, inference=None, **kwargs)

Estimate the counterfactual model from data, i.e. estimates functions $$\tau(X, T0, T1)$$, $$\partial \tau(T, X)$$.

Note that the signature of this method may vary in subclasses (e.g. classes that don’t support instruments will not allow a Z argument)

Parameters
• Y ((n, d_y) matrix or vector of length n) – Outcomes for each sample

• T ((n, d_t) matrix or vector of length n) – Treatments for each sample

• X (optional (n, d_x) matrix) – Features for each sample

• W (optional (n, d_w) matrix) – Controls for each sample

• Z (optional (n, d_z) matrix) – Instruments for each sample

• inference (optional string, Inference instance, or None) – Method for performing inference. All estimators support 'bootstrap' (or an instance of BootstrapInference), some support other methods as well.

Returns

Return type

self

intercept__inference()[source]

The inference of intercept in the linear model of the constant marginal treatment effect.

Returns

InferenceResults – The inference of the intercept in the final linear model

Return type

object

intercept__interval(*, alpha=0.1)[source]

The intercept in the linear model of the constant marginal treatment effect.

Parameters

alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and upper bounds of the confidence interval.

Return type

tuple(type of intercept_(), type of intercept_())

marginal_ate(T, X=None)

Calculate the average marginal effect $$E_{T, X}[\partial\tau(T, X)]$$.

The marginal effect is calculated around a base treatment point and averaged over the population of X.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Average marginal effects on each outcome Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will be a scalar)

Return type

(d_y, d_t) array

marginal_ate_inference(T, X=None)

Inference results for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_ate_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_ate(T, X), type of marginal_ate(T, X) )

abstract marginal_effect(T, X=None)

Calculate the heterogeneous marginal effect $$\partial\tau(T, X)$$.

The marginal effect is calculated around a base treatment point conditional on a vector of features on a set of m test samples $$\{T_i, X_i\}$$.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Heterogeneous marginal effects on each outcome for each sample Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will also be a vector)

Return type

(m, d_y, d_t) array

marginal_effect_inference(T, X=None)

Inference results for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_effect_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_effect(T, X), type of marginal_effect(T, X) )

shap_values(X, *, feature_names=None, treatment_names=None, output_names=None, background_samples=100)[source]

Shap value for the final stage models (const_marginal_effect)

Parameters
• X ((m, d_x) matrix) – Features for each sample. Should be in the same shape of fitted X in final stage.

• feature_names (optional None or list of strings of length X.shape[1] (Default=None)) – The names of input features.

• treatment_names (optional None or list (Default=None)) – The name of treatment. In discrete treatment scenario, the name should not include the name of the baseline treatment (i.e. the control treatment, which by default is the alphabetically smaller)

• output_names (optional None or list (Default=None)) – The name of the outcome.

• background_samples (int or None, (Default=100)) – How many samples to use to compute the baseline effect. If None then all samples are used.

Returns

shap_outs – A nested dictionary by using each output name (e.g. ‘Y0’, ‘Y1’, … when output_names=None) and each treatment name (e.g. ‘T0’, ‘T1’, … when treatment_names=None) as key and the shap_values explanation object as value. If the input data at fit time also contain metadata, (e.g. are pandas DataFrames), then the column metatdata for the treatments, outcomes and features are used instead of the above defaults (unless the user overrides with explicitly passing the corresponding names).

Return type

nested dictionary of Explanation object

summary(alpha=0.1, value=0, decimals=3, feature_names=None, treatment_names=None, output_names=None)[source]

The summary of coefficient and intercept in the linear model of the constant marginal treatment effect.

Parameters
• alpha (optional float in [0, 1] (default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

• value (optinal float (default=0)) – The mean value of the metric you’d like to test under null hypothesis.

• decimals (optinal int (default=3)) – Number of decimal places to round each column to.

• feature_names (optional list of strings or None (default is None)) – The input of the feature names

• treatment_names (optional list of strings or None (default is None)) – The names of the treatments

• output_names (optional list of strings or None (default is None)) – The names of the outputs

Returns

smry – this holds the summary tables and text, which can be printed or converted to various output formats.

Return type

Summary instance

property coef_

The coefficients in the linear model of the constant marginal treatment effect.

Returns

coef – Where n_x is the number of features that enter the final model (either the dimension of X or the dimension of featurizer.fit_transform(X) if the CATE estimator has a featurizer.), n_t is the number of treatments, n_y is the number of outcomes. Dimensions are omitted if the original input was a vector and not a 2D array. For binary treatment the n_t dimension is also omitted.

Return type

(n_x,) or (n_t, n_x) or (n_y, n_t, n_x) array like

property dowhy

Get an instance of DoWhyWrapper to allow other functionalities from dowhy package. (e.g. causal graph, refutation test, etc.)

Returns

DoWhyWrapper – An instance of DoWhyWrapper

Return type

instance

property intercept_

The intercept in the linear model of the constant marginal treatment effect.

Returns

intercept – Where n_t is the number of treatments, n_y is the number of outcomes. Dimensions are omitted if the original input was a vector and not a 2D array. For binary treatment the n_t dimension is also omitted.

Return type

float or (n_y,) or (n_y, n_t) array like

class econml._cate_estimator.StatsModelsCateEstimatorDiscreteMixin[source]

Mixin class that offers inference=’statsmodels’ options to the CATE estimator that inherits it.

Such an estimator must implement a model_final_ attribute that points to a StatsModelsLinearRegression object that is cloned to fit each discrete treatment target CATE model and a fitted_models_final attribute that returns the list of fitted final models that represent the CATE for each categorical treatment.

ate(X=None, *, T0, T1)

Calculate the average treatment effect $$E_X[\tau(X, T0, T1)]$$.

The effect is calculated between the two treatment points and is averaged over the population of X variables.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Average treatment effects on each outcome Note that when Y is a vector rather than a 2-dimensional array, the result will be a scalar

Return type

float or (d_y,) array

ate_inference(X=None, *, T0, T1)

Inference results for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

ate_interval(X=None, *, T0, T1, alpha=0.1)

Confidence intervals for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of ate(X, T0, T1), type of ate(X, T0, T1)) )

cate_feature_names(feature_names=None)

Public interface for getting feature names.

To be overriden by estimators that apply transformations the input features.

Parameters

feature_names (list of strings of length X.shape[1] or None) – The names of the input features. If None and X is a dataframe, it defaults to the column names from the dataframe.

Returns

out_feature_names – Returns feature names.

Return type

list of strings or None

cate_output_names(output_names=None)

Public interface for getting output names.

To be overriden by estimators that apply transformations the outputs.

Parameters

output_names (list of strings of length Y.shape[1] or None) – The names of the outcomes. If None and the Y passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

output_names – Returns output names.

Return type

list of strings

cate_treatment_names(treatment_names=None)

Public interface for getting treatment names.

To be overriden by estimators that apply transformations the treatments.

Parameters

treatment_names (list of strings of length T.shape[1] or None) – The names of the treatments. If None and the T passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

treatment_names – Returns treatment names.

Return type

list of strings

coef_(T)

The coefficients in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters

T (alphanumeric) – The input treatment for which we want the coefficients.

Returns

coef – Where n_x is the number of features that enter the final model (either the dimension of X or the dimension of featurizer.fit_transform(X) if the CATE estimator has a featurizer.)

Return type

(n_x,) or (n_y, n_x) array like

coef__inference(T)

The inference for the coefficients in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters

T (alphanumeric) – The input treatment for which we want the coefficients.

Returns

InferenceResults – The inference of the coefficients in the final linear model

Return type

object

coef__interval(T, *, alpha=0.1)

The confidence interval for the coefficients in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters
• T (alphanumeric) – The input treatment for which we want the coefficients.

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and upper bounds of the confidence interval for each quantity.

Return type

tuple(type of coef_(T), type of coef_(T))

abstract effect(X=None, *, T0, T1)

Calculate the heterogeneous treatment effect $$\tau(X, T0, T1)$$.

The effect is calculated between the two treatment points conditional on a vector of features on a set of m test samples $$\{T0_i, T1_i, X_i\}$$.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Heterogeneous treatment effects on each outcome for each sample Note that when Y is a vector rather than a 2-dimensional array, the corresponding singleton dimension will be collapsed (so this method will return a vector)

Return type

(m, d_y) matrix

effect_inference(X=None, *, T0=0, T1=1)

Inference results for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

effect_interval(X=None, *, T0=0, T1=1, alpha=0.1)

Confidence intervals for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of effect(X, T0, T1), type of effect(X, T0, T1)) )

abstract fit(*args, inference=None, **kwargs)

Estimate the counterfactual model from data, i.e. estimates functions $$\tau(X, T0, T1)$$, $$\partial \tau(T, X)$$.

Note that the signature of this method may vary in subclasses (e.g. classes that don’t support instruments will not allow a Z argument)

Parameters
• Y ((n, d_y) matrix or vector of length n) – Outcomes for each sample

• T ((n, d_t) matrix or vector of length n) – Treatments for each sample

• X (optional (n, d_x) matrix) – Features for each sample

• W (optional (n, d_w) matrix) – Controls for each sample

• Z (optional (n, d_z) matrix) – Instruments for each sample

• inference (optional string, Inference instance, or None) – Method for performing inference. All estimators support 'bootstrap' (or an instance of BootstrapInference), some support other methods as well.

Returns

Return type

self

intercept_(T)

The intercept in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters

T (alphanumeric) – The input treatment for which we want the coefficients.

Returns

intercept

Return type

float or (n_y,) array like

intercept__inference(T)

The inference of the intercept in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters

T (alphanumeric) – The input treatment for which we want the coefficients.

Returns

InferenceResults – The inference of the intercept in the final linear model

Return type

object

intercept__interval(T, *, alpha=0.1)

The intercept in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters
• T (alphanumeric) – The input treatment for which we want the coefficients.

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and upper bounds of the confidence interval.

Return type

tuple(type of intercept_(T), type of intercept_(T))

marginal_ate(T, X=None)

Calculate the average marginal effect $$E_{T, X}[\partial\tau(T, X)]$$.

The marginal effect is calculated around a base treatment point and averaged over the population of X.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Average marginal effects on each outcome Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will be a scalar)

Return type

(d_y, d_t) array

marginal_ate_inference(T, X=None)

Inference results for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_ate_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_ate(T, X), type of marginal_ate(T, X) )

abstract marginal_effect(T, X=None)

Calculate the heterogeneous marginal effect $$\partial\tau(T, X)$$.

The marginal effect is calculated around a base treatment point conditional on a vector of features on a set of m test samples $$\{T_i, X_i\}$$.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Heterogeneous marginal effects on each outcome for each sample Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will also be a vector)

Return type

(m, d_y, d_t) array

marginal_effect_inference(T, X=None)

Inference results for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_effect_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_effect(T, X), type of marginal_effect(T, X) )

summary(T, *, alpha=0.1, value=0, decimals=3, feature_names=None, treatment_names=None, output_names=None)

The summary of coefficient and intercept in the linear model of the constant marginal treatment effect associated with treatment T.

Parameters
• alpha (optional float in [0, 1] (default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

• value (optinal float (default=0)) – The mean value of the metric you’d like to test under null hypothesis.

• decimals (optinal int (default=3)) – Number of decimal places to round each column to.

• feature_names (optional list of strings or None (default is None)) – The input of the feature names

• treatment_names (optional list of strings or None (default is None)) – The names of the treatments

• output_names (optional list of strings or None (default is None)) – The names of the outputs

Returns

smry – this holds the summary tables and text, which can be printed or converted to various output formats.

Return type

Summary instance

property dowhy

Get an instance of DoWhyWrapper to allow other functionalities from dowhy package. (e.g. causal graph, refutation test, etc.)

Returns

DoWhyWrapper – An instance of DoWhyWrapper

Return type

instance

class econml._cate_estimator.StatsModelsCateEstimatorMixin[source]

Mixin class that offers inference=’statsmodels’ options to the CATE estimator that inherits it.

Such an estimator must implement a model_final_ attribute that points to the fitted final StatsModelsLinearRegression object that represents the fitted CATE model. Also must implement featurizer_ that points to the fitted featurizer and bias_part_of_coef that designates if the intercept is the first element of the model_final_ coefficient.

ate(X=None, *, T0, T1)

Calculate the average treatment effect $$E_X[\tau(X, T0, T1)]$$.

The effect is calculated between the two treatment points and is averaged over the population of X variables.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Average treatment effects on each outcome Note that when Y is a vector rather than a 2-dimensional array, the result will be a scalar

Return type

float or (d_y,) array

ate_inference(X=None, *, T0, T1)

Inference results for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

ate_interval(X=None, *, T0, T1, alpha=0.1)

Confidence intervals for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of ate(X, T0, T1), type of ate(X, T0, T1)) )

cate_feature_names(feature_names=None)

Public interface for getting feature names.

To be overriden by estimators that apply transformations the input features.

Parameters

feature_names (list of strings of length X.shape[1] or None) – The names of the input features. If None and X is a dataframe, it defaults to the column names from the dataframe.

Returns

out_feature_names – Returns feature names.

Return type

list of strings or None

cate_output_names(output_names=None)

Public interface for getting output names.

To be overriden by estimators that apply transformations the outputs.

Parameters

output_names (list of strings of length Y.shape[1] or None) – The names of the outcomes. If None and the Y passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

output_names – Returns output names.

Return type

list of strings

cate_treatment_names(treatment_names=None)

Public interface for getting treatment names.

To be overriden by estimators that apply transformations the treatments.

Parameters

treatment_names (list of strings of length T.shape[1] or None) – The names of the treatments. If None and the T passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

treatment_names – Returns treatment names.

Return type

list of strings

coef__inference()

The inference of coefficients in the linear model of the constant marginal treatment effect.

Returns

InferenceResults – The inference of the coefficients in the final linear model

Return type

object

coef__interval(*, alpha=0.1)

The coefficients in the linear model of the constant marginal treatment effect.

Parameters

alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lb, ub – The lower and upper bounds of the confidence interval for each quantity.

Return type

tuple(type of coef_(), type of coef_())

abstract effect(X=None, *, T0, T1)

Calculate the heterogeneous treatment effect $$\tau(X, T0, T1)$$.

The effect is calculated between the two treatment points conditional on a vector of features on a set of m test samples $$\{T0_i, T1_i, X_i\}$$.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Heterogeneous treatment effects on each outcome for each sample Note that when Y is a vector rather than a 2-dimensional array, the corresponding singleton dimension will be collapsed (so this method will return a vector)

Return type

(m, d_y) matrix

effect_inference(X=None, *, T0=0, T1=1)

Inference results for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

effect_interval(X=None, *, T0=0, T1=1, alpha=0.1)

Confidence intervals for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of effect(X, T0, T1), type of effect(X, T0, T1)) )

abstract fit(*args, inference=None, **kwargs)

Estimate the counterfactual model from data, i.e. estimates functions $$\tau(X, T0, T1)$$, $$\partial \tau(T, X)$$.

Note that the signature of this method may vary in subclasses (e.g. classes that don’t support instruments will not allow a Z argument)

Parameters
• Y ((n, d_y) matrix or vector of length n) – Outcomes for each sample

• T ((n, d_t) matrix or vector of length n) – Treatments for each sample

• X (optional (n, d_x) matrix) – Features for each sample

• W (optional (n, d_w) matrix) – Controls for each sample

• Z (optional (n, d_z) matrix) – Instruments for each sample

• inference (optional string, Inference instance, or None) – Method for performing inference. All estimators support 'bootstrap' (or an instance of BootstrapInference), some support other methods as well.

Returns

Return type

self

intercept__inference()

The inference of intercept in the linear model of the constant marginal treatment effect.

Returns

InferenceResults – The inference of the intercept in the final linear model

Return type

object

intercept__interval(*, alpha=0.1)

The intercept in the linear model of the constant marginal treatment effect.

Parameters

alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and upper bounds of the confidence interval.

Return type

tuple(type of intercept_(), type of intercept_())

marginal_ate(T, X=None)

Calculate the average marginal effect $$E_{T, X}[\partial\tau(T, X)]$$.

The marginal effect is calculated around a base treatment point and averaged over the population of X.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Average marginal effects on each outcome Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will be a scalar)

Return type

(d_y, d_t) array

marginal_ate_inference(T, X=None)

Inference results for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_ate_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_ate(T, X), type of marginal_ate(T, X) )

abstract marginal_effect(T, X=None)

Calculate the heterogeneous marginal effect $$\partial\tau(T, X)$$.

The marginal effect is calculated around a base treatment point conditional on a vector of features on a set of m test samples $$\{T_i, X_i\}$$.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Heterogeneous marginal effects on each outcome for each sample Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will also be a vector)

Return type

(m, d_y, d_t) array

marginal_effect_inference(T, X=None)

Inference results for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_effect_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_effect(T, X), type of marginal_effect(T, X) )

shap_values(X, *, feature_names=None, treatment_names=None, output_names=None, background_samples=100)

Shap value for the final stage models (const_marginal_effect)

Parameters
• X ((m, d_x) matrix) – Features for each sample. Should be in the same shape of fitted X in final stage.

• feature_names (optional None or list of strings of length X.shape[1] (Default=None)) – The names of input features.

• treatment_names (optional None or list (Default=None)) – The name of treatment. In discrete treatment scenario, the name should not include the name of the baseline treatment (i.e. the control treatment, which by default is the alphabetically smaller)

• output_names (optional None or list (Default=None)) – The name of the outcome.

• background_samples (int or None, (Default=100)) – How many samples to use to compute the baseline effect. If None then all samples are used.

Returns

shap_outs – A nested dictionary by using each output name (e.g. ‘Y0’, ‘Y1’, … when output_names=None) and each treatment name (e.g. ‘T0’, ‘T1’, … when treatment_names=None) as key and the shap_values explanation object as value. If the input data at fit time also contain metadata, (e.g. are pandas DataFrames), then the column metatdata for the treatments, outcomes and features are used instead of the above defaults (unless the user overrides with explicitly passing the corresponding names).

Return type

nested dictionary of Explanation object

summary(alpha=0.1, value=0, decimals=3, feature_names=None, treatment_names=None, output_names=None)

The summary of coefficient and intercept in the linear model of the constant marginal treatment effect.

Parameters
• alpha (optional float in [0, 1] (default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

• value (optinal float (default=0)) – The mean value of the metric you’d like to test under null hypothesis.

• decimals (optinal int (default=3)) – Number of decimal places to round each column to.

• feature_names (optional list of strings or None (default is None)) – The input of the feature names

• treatment_names (optional list of strings or None (default is None)) – The names of the treatments

• output_names (optional list of strings or None (default is None)) – The names of the outputs

Returns

smry – this holds the summary tables and text, which can be printed or converted to various output formats.

Return type

Summary instance

property coef_

The coefficients in the linear model of the constant marginal treatment effect.

Returns

coef – Where n_x is the number of features that enter the final model (either the dimension of X or the dimension of featurizer.fit_transform(X) if the CATE estimator has a featurizer.), n_t is the number of treatments, n_y is the number of outcomes. Dimensions are omitted if the original input was a vector and not a 2D array. For binary treatment the n_t dimension is also omitted.

Return type

(n_x,) or (n_t, n_x) or (n_y, n_t, n_x) array like

property dowhy

Get an instance of DoWhyWrapper to allow other functionalities from dowhy package. (e.g. causal graph, refutation test, etc.)

Returns

DoWhyWrapper – An instance of DoWhyWrapper

Return type

instance

property intercept_

The intercept in the linear model of the constant marginal treatment effect.

Returns

intercept – Where n_t is the number of treatments, n_y is the number of outcomes. Dimensions are omitted if the original input was a vector and not a 2D array. For binary treatment the n_t dimension is also omitted.

Return type

float or (n_y,) or (n_y, n_t) array like

class econml._cate_estimator.TreatmentExpansionMixin[source]

Mixin which automatically handles promotions of scalar treatments to the appropriate shape.

ate(X=None, *, T0=0, T1=1)[source]

Calculate the average treatment effect $$E_X[\tau(X, T0, T1)]$$.

The effect is calculated between the two treatment points and is averaged over the population of X variables.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Average treatment effects on each outcome Note that when Y is a vector rather than a 2-dimensional array, the result will be a scalar

Return type

float or (d_y,) array

ate_inference(X=None, *, T0=0, T1=1)[source]

Inference results for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

ate_interval(X=None, *, T0=0, T1=1, alpha=0.1)[source]

Confidence intervals for the quantity $$E_X[\tau(X, T0, T1)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of ate(X, T0, T1), type of ate(X, T0, T1)) )

cate_feature_names(feature_names=None)

Public interface for getting feature names.

To be overriden by estimators that apply transformations the input features.

Parameters

feature_names (list of strings of length X.shape[1] or None) – The names of the input features. If None and X is a dataframe, it defaults to the column names from the dataframe.

Returns

out_feature_names – Returns feature names.

Return type

list of strings or None

cate_output_names(output_names=None)

Public interface for getting output names.

To be overriden by estimators that apply transformations the outputs.

Parameters

output_names (list of strings of length Y.shape[1] or None) – The names of the outcomes. If None and the Y passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

output_names – Returns output names.

Return type

list of strings

cate_treatment_names(treatment_names=None)[source]

Get treatment names.

If the treatment is discrete, it will return expanded treatment names.

Parameters

treatment_names (list of strings of length T.shape[1] or None) – The names of the treatments. If None and the T passed to fit was a dataframe, it defaults to the column names from the dataframe.

Returns

out_treatment_names – Returns (possibly expanded) treatment names.

Return type

list of strings

effect(X=None, *, T0=0, T1=1)[source]

Calculate the heterogeneous treatment effect $$\tau(X, T0, T1)$$.

The effect is calculated between the two treatment points conditional on a vector of features on a set of m test samples $$\{T0_i, T1_i, X_i\}$$.

Parameters
• T0 ((m, d_t) matrix or vector of length m) – Base treatments for each sample

• T1 ((m, d_t) matrix or vector of length m) – Target treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

τ – Heterogeneous treatment effects on each outcome for each sample Note that when Y is a vector rather than a 2-dimensional array, the corresponding singleton dimension will be collapsed (so this method will return a vector)

Return type

(m, d_y) matrix

effect_inference(X=None, *, T0=0, T1=1)

Inference results for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

effect_interval(X=None, *, T0=0, T1=1, alpha=0.1)

Confidence intervals for the quantities $$\tau(X, T0, T1)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• X (optional (m, d_x) matrix) – Features for each sample

• T0 (optional (m, d_t) matrix or vector of length m (Default=0)) – Base treatments for each sample

• T1 (optional (m, d_t) matrix or vector of length m (Default=1)) – Target treatments for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of effect(X, T0, T1), type of effect(X, T0, T1)) )

abstract fit(*args, inference=None, **kwargs)

Estimate the counterfactual model from data, i.e. estimates functions $$\tau(X, T0, T1)$$, $$\partial \tau(T, X)$$.

Note that the signature of this method may vary in subclasses (e.g. classes that don’t support instruments will not allow a Z argument)

Parameters
• Y ((n, d_y) matrix or vector of length n) – Outcomes for each sample

• T ((n, d_t) matrix or vector of length n) – Treatments for each sample

• X (optional (n, d_x) matrix) – Features for each sample

• W (optional (n, d_w) matrix) – Controls for each sample

• Z (optional (n, d_z) matrix) – Instruments for each sample

• inference (optional string, Inference instance, or None) – Method for performing inference. All estimators support 'bootstrap' (or an instance of BootstrapInference), some support other methods as well.

Returns

Return type

self

marginal_ate(T, X=None)

Calculate the average marginal effect $$E_{T, X}[\partial\tau(T, X)]$$.

The marginal effect is calculated around a base treatment point and averaged over the population of X.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Average marginal effects on each outcome Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will be a scalar)

Return type

(d_y, d_t) array

marginal_ate_inference(T, X=None)

Inference results for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

PopulationSummaryResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_ate_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$E_{T,X}[\partial \tau(T, X)]$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_ate(T, X), type of marginal_ate(T, X) )

abstract marginal_effect(T, X=None)

Calculate the heterogeneous marginal effect $$\partial\tau(T, X)$$.

The marginal effect is calculated around a base treatment point conditional on a vector of features on a set of m test samples $$\{T_i, X_i\}$$.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix) – Features for each sample

Returns

grad_tau – Heterogeneous marginal effects on each outcome for each sample Note that when Y or T is a vector rather than a 2-dimensional array, the corresponding singleton dimensions in the output will be collapsed (e.g. if both are vectors, then the output of this method will also be a vector)

Return type

(m, d_y, d_t) array

marginal_effect_inference(T, X=None)

Inference results for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

Returns

InferenceResults – The inference results instance contains prediction and prediction standard error and can on demand calculate confidence interval, z statistic and p value. It can also output a dataframe summary of these inference results.

Return type

object

marginal_effect_interval(T, X=None, *, alpha=0.1)

Confidence intervals for the quantities $$\partial \tau(T, X)$$ produced by the model. Available only when inference is not None, when calling the fit method.

Parameters
• T ((m, d_t) matrix) – Base treatments for each sample

• X (optional (m, d_x) matrix or None (Default=None)) – Features for each sample

• alpha (optional float in [0, 1] (Default=0.1)) – The overall level of confidence of the reported interval. The alpha/2, 1-alpha/2 confidence interval is reported.

Returns

lower, upper – The lower and the upper bounds of the confidence interval for each quantity.

Return type

tuple(type of marginal_effect(T, X), type of marginal_effect(T, X) )

property dowhy

Get an instance of DoWhyWrapper to allow other functionalities from dowhy package. (e.g. causal graph, refutation test, etc.)

Returns

DoWhyWrapper – An instance of DoWhyWrapper

Return type

instance