# econml.dml¶

Double Machine Learning. The method uses machine learning methods to identify the part of the observed outcome and treatment that is not predictable by the controls X, W (aka residual outcome and residual treatment). Then estimates a CATE model by regressing the residual outcome on the residual treatment in a manner that accounts for heterogeneity in the regression coefficient, with respect to X.

References

V. Chernozhukov, D. Chetverikov, M. Demirer, E. Duflo, C. Hansen, and a. W. Newey.

Double Machine Learning for Treatment and Causal Parameters. https://arxiv.org/abs/1608.00060, 2016.

X. Nie and S. Wager.

Quasi-Oracle Estimation of Heterogeneous Treatment Effects. arXiv preprint arXiv:1712.04912, 2017. URL http://arxiv.org/abs/1712.04912.

V. Chernozhukov, M. Goldman, V. Semenova, and M. Taddy.

Orthogonal Machine Learning for Demand Estimation: High Dimensional Causal Inference in Dynamic Panels. https://arxiv.org/abs/1712.09988, December 2017.

V. Chernozhukov, D. Nekipelov, V. Semenova, and V. Syrgkanis.

Two-Stage Estimation with a High-Dimensional Second Stage. https://arxiv.org/abs/1806.04823, 2018.

Dylan Foster, Vasilis Syrgkanis (2019).

Orthogonal Statistical Learning. ACM Conference on Learning Theory. https://arxiv.org/abs/1901.09036

Classes

 DMLCateEstimator(model_y, model_t, model_final) The base class for parametric Double ML estimators. ForestDMLCateEstimator(model_y, model_t[, …]) Instance of NonParamDMLCateEstimator with a SubsampledHonestForest as a final model, so as to enable non-parametric inference. KernelDMLCateEstimator([model_y, model_t, …]) A specialized version of the linear Double ML Estimator that uses random fourier features. LinearDMLCateEstimator([model_y, model_t, …]) The Double ML Estimator with a low-dimensional linear final stage implemented as a statsmodel regression. NonParamDMLCateEstimator(model_y, model_t, …) The base class for non-parametric Double ML estimators, that can have arbitrary final ML models of the CATE. SparseLinearDMLCateEstimator([model_y, …]) A specialized version of the Double ML estimator for the sparse linear case.
class econml.dml.DMLCateEstimator(model_y, model_t, model_final, featurizer=None, fit_cate_intercept=True, linear_first_stages=False, discrete_treatment=False, n_splits=2, random_state=None)[source]

Bases: econml.dml._BaseDMLCateEstimator

The base class for parametric Double ML estimators. The estimator is a special case of an _RLearner estimator, which in turn is a special case of an _OrthoLearner estimator, so it follows the two stage process, where a set of nuisance functions are estimated in the first stage in a crossfitting manner and a final stage estimates the CATE model. See the documentation of _OrthoLearner for a description of this two stage process.

In this estimator, the CATE is estimated by using the following estimating equations:

$Y - \E[Y | X, W] = \Theta(X) \cdot (T - \E[T | X, W]) + \epsilon$

Thus if we estimate the nuisance functions $$q(X, W) = \E[Y | X, W]$$ and $$f(X, W)=\E[T | X, W]$$ in the first stage, we can estimate the final stage cate for each treatment t, by running a regression, minimizing the residual on residual square loss:

$\hat{\theta} = \arg\min_{\Theta} \E_n\left[ (\tilde{Y} - \Theta(X) \cdot \tilde{T})^2 \right]$

Where $$\tilde{Y}=Y - \E[Y | X, W]$$ and $$\tilde{T}=T-\E[T | X, W]$$ denotes the residual outcome and residual treatment.

The DMLCateEstimator further assumes a linear parametric form for the cate, i.e. for each outcome $$i$$ and treatment $$j$$:

$\Theta_{i, j}(X) = \phi(X)' \cdot \Theta_{ij}$

For some given feature mapping $$\phi(X)$$ (the user can provide this featurizer via the featurizer parameter at init time and could be any arbitrary class that adheres to the scikit-learn transformer interface TransformerMixin).

The second nuisance function $$q$$ is a simple regression problem and the DMLCateEstimator class takes as input the parameter model_y, which is an arbitrary scikit-learn regressor that is internally used to solve this regression problem.

The problem of estimating the nuisance function $$f$$ is also a regression problem and the DMLCateEstimator class takes as input the parameter model_t, which is an arbitrary scikit-learn regressor that is internally used to solve this regression problem. If the init flag discrete_treatment is set to True, then the parameter model_t is treated as a scikit-learn classifier. The input categorical treatment is one-hot encoded (excluding the lexicographically smallest treatment which is used as the baseline) and the predict_proba method of the model_t classifier is used to residualize the one-hot encoded treatment.

The final stage is (potentially multi-task) linear regression problem with outcomes the labels $$\tilde{Y}$$ and regressors the composite features $$\tilde{T}\otimes \phi(X) = \mathtt{vec}(\tilde{T}\cdot \phi(X)^T)$$. The DMLCateEstimator takes as input parameter model_final, which is any linear scikit-learn regressor that is internally used to solve this (multi-task) linear regresion problem.

Parameters
• model_y (estimator) – The estimator for fitting the response to the features. Must implement fit and predict methods. Must be a linear model for correctness when linear_first_stages is True.

• model_t (estimator or ‘auto’ (default is ‘auto’)) – The estimator for fitting the treatment to the features. If estimator, it must implement fit and predict methods. Must be a linear model for correctness when linear_first_stages is True; If ‘auto’, LogisticRegressionCV will be applied for discrete treatment, and WeightedLassoCV/ WeightedMultiTaskLassoCV will be applied for continuous treatment.

• model_final (estimator) – The estimator for fitting the response residuals to the treatment residuals. Must implement fit and predict methods, and must be a linear model for correctness.

• featurizer (transformer, optional, default None) – Must support fit_transform and transform. Used to create composite features in the final CATE regression. It is ignored if X is None. The final CATE will be trained on the outcome of featurizer.fit_transform(X). If featurizer=None, then CATE is trained on X.

• fit_cate_intercept (bool, optional, default True) – Whether the linear CATE model should have a constant term.

• linear_first_stages (bool) – Whether the first stage models are linear (in which case we will expand the features passed to model_y accordingly)

• discrete_treatment (bool, optional, default False) – Whether the treatment values should be treated as categorical, rather than continuous, quantities

• n_splits (int, cross-validation generator or an iterable, optional, default 2) – Determines the cross-validation splitting strategy. Possible inputs for cv are:

• None, to use the default 3-fold cross-validation,

• integer, to specify the number of folds.

• CV splitter

• An iterable yielding (train, test) splits as arrays of indices.

For integer/None inputs, if the treatment is discrete StratifiedKFold is used, else, KFold is used (with a random shuffle in either case).

Unless an iterable is used, we call split(concat[W, X], T) to generate the splits. If all W, X are None, then we call split(ones((T.shape[0], 1)), T).

• random_state (int, RandomState instance or None, optional (default=None)) – If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

cate_feature_names(input_feature_names=None)

Get the output feature names.

Parameters

input_feature_names (list of strings of length X.shape[1] or None) – The names of the input features

Returns

out_feature_names – The names of the output features $$\phi(X)$$, i.e. the features with respect to which the final constant marginal CATE model is linear. It is the names of the features that are associated with each entry of the coef_() parameter. Not available when the featurizer is not None and does not have a method: get_feature_names(input_feature_names). Otherwise None is returned.

Return type

list of strings or None

const_marginal_effect(X=None)

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)

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)

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=0, T1=1)

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)) )

fit(Y, T, X=None, W=None, *, sample_weight=None, sample_var=None, inference=None)

Estimate the counterfactual model from data, i.e. estimates function $$\theta(\cdot)$$.

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 or None (Default=None)) – Features for each sample

• W (optional(n, d_w) matrix or None (Default=None)) – Controls for each sample

• sample_weight (optional(n,) vector or None (Default=None)) – Weights for each samples

• sample_var (optional(n,) vector or None (Default=None)) – Sample variance for each sample

• inference (string,:class:.Inference instance, or None) – Method for performing inference. This estimator supports ‘bootstrap’ (or an instance of:class:.BootstrapInference).

Returns

self

Return type

_RLearner instance

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\}$$. 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)

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) )

score(Y, T, X=None, W=None)

Score the fitted CATE model on a new data set. Generates nuisance parameters for the new data set based on the fitted residual nuisance models created at fit time. It uses the mean prediction of the models fitted by the different crossfit folds. Then calculates the MSE of the final residual Y on residual T regression.

If model_final does not have a score method, then it raises an AttributeError

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 or None (Default=None)) – Features for each sample

• W (optional(n, d_w) matrix or None (Default=None)) – Controls for each sample

Returns

score – The MSE of the final CATE model on the new data.

Return type

float

property model_cate

Get the fitted final CATE model.

Returns

model_cate – An instance of the model_final object that was fitted after calling fit which corresponds to the constant marginal CATE model.

Return type

object of type(model_final)

property models_t

Get the fitted models for E[T | X, W].

Returns

models_y – A list of instances of the model_y object. Each element corresponds to a crossfitting fold and is the model instance that was fitted for that training fold.

Return type

list of objects of type(model_t)

property models_y

Get the fitted models for E[Y | X, W].

Returns

models_y – A list of instances of the model_y object. Each element corresponds to a crossfitting fold and is the model instance that was fitted for that training fold.

Return type

list of objects of type(model_y)

class econml.dml.ForestDMLCateEstimator(model_y, model_t, discrete_treatment=False, n_crossfit_splits=2, n_estimators=100, criterion='mse', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features='auto', max_leaf_nodes=None, min_impurity_decrease=0.0, subsample_fr='auto', honest=True, n_jobs=None, verbose=0, random_state=None)[source]

Instance of NonParamDMLCateEstimator with a SubsampledHonestForest as a final model, so as to enable non-parametric inference.

Parameters
• model_y (estimator) – The estimator for fitting the response to the features. Must implement fit and predict methods. Must be a linear model for correctness when linear_first_stages is True.

• model_t (estimator) – The estimator for fitting the treatment to the features. Must implement fit and predict methods. Must be a linear model for correctness when linear_first_stages is True.

• discrete_treatment (bool, optional (default is False)) – Whether the treatment values should be treated as categorical, rather than continuous, quantities

• n_crossfit_splits (int, cross-validation generator or an iterable, optional (Default=2)) – Determines the cross-validation splitting strategy. Possible inputs for cv are:

• None, to use the default 3-fold cross-validation,

• integer, to specify the number of folds.

• CV splitter

• An iterable yielding (train, test) splits as arrays of indices.

For integer/None inputs, if the treatment is discrete StratifiedKFold is used, else, KFold is used (with a random shuffle in either case).

Unless an iterable is used, we call split(concat[W, X], T) to generate the splits. If all W, X are None, then we call split(ones((T.shape[0], 1)), T).

• n_estimators (integer, optional (default=100)) – The total number of trees in the forest. The forest consists of a forest of sqrt(n_estimators) sub-forests, where each sub-forest contains sqrt(n_estimators) trees.

• criterion (string, optional (default=”mse”)) – The function to measure the quality of a split. Supported criteria are “mse” for the mean squared error, which is equal to variance reduction as feature selection criterion, and “mae” for the mean absolute error.

• max_depth (integer or None, optional (default=None)) – The maximum depth of the tree. If None, then nodes are expanded until all leaves are pure or until all leaves contain less than min_samples_split samples.

• min_samples_split (int, float, optional (default=2)) – The minimum number of splitting samples required to split an internal node.

• If int, then consider min_samples_split as the minimum number.

• If float, then min_samples_split is a fraction and ceil(min_samples_split * n_samples) are the minimum number of samples for each split.

• min_samples_leaf (int, float, optional (default=1)) – The minimum number of samples required to be at a leaf node. A split point at any depth will only be considered if it leaves at least min_samples_leaf splitting samples in each of the left and right branches. This may have the effect of smoothing the model, especially in regression. After construction the tree is also pruned so that there are at least min_samples_leaf estimation samples on each leaf.

• If int, then consider min_samples_leaf as the minimum number.

• If float, then min_samples_leaf is a fraction and ceil(min_samples_leaf * n_samples) are the minimum number of samples for each node.

• min_weight_fraction_leaf (float, optional (default=0.)) – The minimum weighted fraction of the sum total of weights (of all splitting samples) required to be at a leaf node. Samples have equal weight when sample_weight is not provided. After construction the tree is pruned so that the fraction of the sum total weight of the estimation samples contained in each leaf node is at least min_weight_fraction_leaf

• max_features (int, float, string or None, optional (default=”auto”)) – The number of features to consider when looking for the best split:

• If int, then consider max_features features at each split.

• If float, then max_features is a fraction and int(max_features * n_features) features are considered at each split.

• If “auto”, then max_features=n_features.

• If “sqrt”, then max_features=sqrt(n_features).

• If “log2”, then max_features=log2(n_features).

• If None, then max_features=n_features.

Note: the search for a split does not stop until at least one valid partition of the node samples is found, even if it requires to effectively inspect more than max_features features.

• max_leaf_nodes (int or None, optional (default=None)) – Grow trees with max_leaf_nodes in best-first fashion. Best nodes are defined as relative reduction in impurity. If None then unlimited number of leaf nodes.

• min_impurity_decrease (float, optional (default=0.)) – A node will be split if this split induces a decrease of the impurity greater than or equal to this value.

The weighted impurity decrease equation is the following:

N_t / N * (impurity - N_t_R / N_t * right_impurity
- N_t_L / N_t * left_impurity)


where N is the total number of split samples, N_t is the number of split samples at the current node, N_t_L is the number of split samples in the left child, and N_t_R is the number of split samples in the right child.

N, N_t, N_t_R and N_t_L all refer to the weighted sum, if sample_weight is passed.

• subsample_fr (float or ‘auto’, optional (default=’auto’)) – The fraction of the half-samples that are used on each tree. Each tree will be built on subsample_fr * n_samples/2.

If ‘auto’, then the subsampling fraction is set to:

(n_samples/2)**(1-1/(2*n_features+2))/(n_samples/2)


which is sufficient to guarantee asympotitcally valid inference.

• honest (boolean, optional (default=True)) – Whether to use honest trees, i.e. half of the samples are used for creating the tree structure and the other half for the estimation at the leafs. If False, then all samples are used for both parts.

• n_jobs (int or None, optional (default=None)) – The number of jobs to run in parallel for both fit and predict. None means 1 unless in a joblib.parallel_backend() context. -1 means using all processors. See Glossary for more details.

• verbose (int, optional (default=0)) – Controls the verbosity when fitting and predicting.

• random_state (int, RandomState instance or None, optional (default=None)) – If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

cate_feature_names(input_feature_names=None)

Get the output feature names.

Parameters

input_feature_names (list of strings of length X.shape[1] or None) – The names of the input features

Returns

out_feature_names – The names of the output features $$\phi(X)$$, i.e. the features with respect to which the final constant marginal CATE model is linear. It is the names of the features that are associated with each entry of the coef_() parameter. Not available when the featurizer is not None and does not have a method: get_feature_names(input_feature_names). Otherwise None is returned.

Return type

list of strings or None

const_marginal_effect(X=None)

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)

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)

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=0, T1=1)

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)) )

fit(Y, T, X=None, W=None, sample_weight=None, sample_var=None, inference=None)[source]

Estimate the counterfactual model from data, i.e. estimates functions τ(·,·,·), ∂τ(·,·).

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

• T ((n × dₜ) matrix or vector of length n) – Treatments for each sample

• X (optional (n × dₓ) matrix) – Features for each sample

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

• sample_weight (optional (n,) vector) – Weights for each row

• sample_var (optional (n, n_y) vector) – Variance of sample, in case it corresponds to summary of many samples. Currently not in use by this method (as inference method does not require sample variance info).

• inference (string, Inference instance, or None) – Method for performing inference. This estimator supports ‘bootstrap’ (or an instance of BootstrapInference) and ‘blb’ (for Bootstrap-of-Little-Bags based inference)

Returns

Return type

self

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\}$$. 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)

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) )

score(Y, T, X=None, W=None)

Score the fitted CATE model on a new data set. Generates nuisance parameters for the new data set based on the fitted residual nuisance models created at fit time. It uses the mean prediction of the models fitted by the different crossfit folds. Then calculates the MSE of the final residual Y on residual T regression.

If model_final does not have a score method, then it raises an AttributeError

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 or None (Default=None)) – Features for each sample

• W (optional(n, d_w) matrix or None (Default=None)) – Controls for each sample

Returns

score – The MSE of the final CATE model on the new data.

Return type

float

property model_cate

Get the fitted final CATE model.

Returns

model_cate – An instance of the model_final object that was fitted after calling fit which corresponds to the constant marginal CATE model.

Return type

object of type(model_final)

property models_t

Get the fitted models for E[T | X, W].

Returns

models_y – A list of instances of the model_y object. Each element corresponds to a crossfitting fold and is the model instance that was fitted for that training fold.

Return type

list of objects of type(model_t)

property models_y

Get the fitted models for E[Y | X, W].

Returns

models_y – A list of instances of the model_y object. Each element corresponds to a crossfitting fold and is the model instance that was fitted for that training fold.

Return type

list of objects of type(model_y)

class econml.dml.KernelDMLCateEstimator(model_y=<econml.sklearn_extensions.linear_model.WeightedLassoCVWrapper object>, model_t='auto', fit_cate_intercept=True, dim=20, bw=1.0, discrete_treatment=False, n_splits=2, random_state=None)[source]

A specialized version of the linear Double ML Estimator that uses random fourier features.

Parameters
• model_y (estimator, optional (default is <econml.sklearn_extensions.linear_model.WeightedLassoCVWrapper>)) – The estimator for fitting the response to the features. Must implement fit and predict methods.

• model_t (estimator or ‘auto’, optional (default is ‘auto’)) – The estimator for fitting the treatment to the features. If estimator, it must implement fit and predict methods; If ‘auto’, LogisticRegressionCV will be applied for discrete treatment, and WeightedLassoCV/ WeightedMultiTaskLassoCV will be applied for continuous treatment.

• fit_cate_intercept (bool, optional, default True) – Whether the linear CATE model should have a constant term.

• dim (int, optional (default is 20)) – The number of random Fourier features to generate

• bw (float, optional (default is 1.0)) – The bandwidth of the Gaussian used to generate features

• discrete_treatment (bool, optional (default is False)) – Whether the treatment values should be treated as categorical, rather than continuous, quantities

• n_splits (int, cross-validation generator or an iterable, optional (Default=2)) – Determines the cross-validation splitting strategy. Possible inputs for cv are:

• None, to use the default 3-fold cross-validation,

• integer, to specify the number of folds.

• CV splitter

• An iterable yielding (train, test) splits as arrays of indices.

For integer/None inputs, if the treatment is discrete StratifiedKFold is used, else, KFold is used (with a random shuffle in either case).

Unless an iterable is used, we call split(X,T) to generate the splits.

• random_state (int, RandomState instance or None, optional (default=None)) – If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

cate_feature_names(input_feature_names=None)

Get the output feature names.

Parameters

input_feature_names (list of strings of length X.shape[1] or None) – The names of the input features

Returns

out_feature_names – The names of the output features $$\phi(X)$$, i.e. the features with respect to which the final constant marginal CATE model is linear. It is the names of the features that are associated with each entry of the coef_() parameter. Not available when the featurizer is not None and does not have a method: get_feature_names(input_feature_names). Otherwise None is returned.

Return type

list of strings or None

const_marginal_effect(X=None)

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)

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)

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=0, T1=1)

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)) )

fit(Y, T, X=None, W=None, *, sample_weight=None, sample_var=None, inference=None)

Estimate the counterfactual model from data, i.e. estimates function $$\theta(\cdot)$$.

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 or None (Default=None)) – Features for each sample

• W (optional(n, d_w) matrix or None (Default=None)) – Controls for each sample

• sample_weight (optional(n,) vector or None (Default=None)) – Weights for each samples

• sample_var (optional(n,) vector or None (Default=None)) – Sample variance for each sample

• inference (string,:class:.Inference instance, or None) – Method for performing inference. This estimator supports ‘bootstrap’ (or an instance of:class:.BootstrapInference).

Returns

self

Return type

_RLearner instance

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\}$$. 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)

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) )

score(Y, T, X=None, W=None)

Score the fitted CATE model on a new data set. Generates nuisance parameters for the new data set based on the fitted residual nuisance models created at fit time. It uses the mean prediction of the models fitted by the different crossfit folds. Then calculates the MSE of the final residual Y on residual T regression.

If model_final does not have a score method, then it raises an AttributeError

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 or None (Default=None)) – Features for each sample

• W (optional(n, d_w) matrix or None (Default=None)) – Controls for each sample

Returns

score – The MSE of the final CATE model on the new data.

Return type

float

property model_cate

Get the fitted final CATE model.

Returns

model_cate – An instance of the model_final object that was fitted after calling fit which corresponds to the constant marginal CATE model.

Return type

object of type(model_final)

property models_t

Get the fitted models for E[T | X, W].

Returns

models_y – A list of instances of the model_y object. Each element corresponds to a crossfitting fold and is the model instance that was fitted for that training fold.

Return type

list of objects of type(model_t)

property models_y

Get the fitted models for E[Y | X, W].

Returns

models_y – A list of instances of the model_y object. Each element corresponds to a crossfitting fold and is the model instance that was fitted for that training fold.

Return type

list of objects of type(model_y)

class econml.dml.LinearDMLCateEstimator(model_y=<econml.sklearn_extensions.linear_model.WeightedLassoCVWrapper object>, model_t='auto', featurizer=None, fit_cate_intercept=True, linear_first_stages=True, discrete_treatment=False, n_splits=2, random_state=None)[source]

The Double ML Estimator with a low-dimensional linear final stage implemented as a statsmodel regression.

Parameters
• model_y (estimator, optional (default is WeightedLassoCVWrapper)) – The estimator for fitting the response to the features. Must implement fit and predict methods.

• model_t (estimator or ‘auto’, optional (default is ‘auto’)) – The estimator for fitting the treatment to the features. If estimator, it must implement fit and predict methods; If ‘auto’, LogisticRegressionCV will be applied for discrete treatment, and WeightedLassoCV/WeightedMultiTaskLassoCV will be applied for continuous treatment.

• featurizer (transformer, optional, default None) – Must support fit_transform and transform. Used to create composite features in the final CATE regression. It is ignored if X is None. The final CATE will be trained on the outcome of featurizer.fit_transform(X). If featurizer=None, then CATE is trained on X.

• fit_cate_intercept (bool, optional, default True) – Whether the linear CATE model should have a constant term.

• linear_first_stages (bool) – Whether the first stage models are linear (in which case we will expand the features passed to model_y accordingly)

• discrete_treatment (bool, optional (default is False)) – Whether the treatment values should be treated as categorical, rather than continuous, quantities

• n_splits (int, cross-validation generator or an iterable, optional (Default=2)) – Determines the cross-validation splitting strategy. Possible inputs for cv are:

• None, to use the default 3-fold cross-validation,

• integer, to specify the number of folds.

• CV splitter

• An iterable yielding (train, test) splits as arrays of indices.

For integer/None inputs, if the treatment is discrete StratifiedKFold is used, else, KFold is used (with a random shuffle in either case).

Unless an iterable is used, we call split(X,T) to generate the splits.

• random_state (int, RandomState instance or None, optional (default=None)) – If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

cate_feature_names(input_feature_names=None)

Get the output feature names.

Parameters

input_feature_names (list of strings of length X.shape[1] or None) – The names of the input features

Returns

out_feature_names – The names of the output features $$\phi(X)$$, i.e. the features with respect to which the final constant marginal CATE model is linear. It is the names of the features that are associated with each entry of the coef_() parameter. Not available when the featurizer is not None and does not have a method: get_feature_names(input_feature_names). Otherwise None is returned.

Return type

list of strings or None

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_())

const_marginal_effect(X=None)

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)

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)

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=0, T1=1)

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)) )

fit(Y, T, X=None, W=None, sample_weight=None, sample_var=None, inference=None)[source]

Estimate the counterfactual model from data, i.e. estimates functions τ(·,·,·), ∂τ(·,·).

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

• T ((n × dₜ) matrix or vector of length n) – Treatments for each sample

• X (optional (n × dₓ) matrix) – Features for each sample

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

• sample_weight (optional (n,) vector) – Weights for each row

• inference (string, Inference instance, or None) – Method for performing inference. This estimator supports ‘bootstrap’ (or an instance of BootstrapInference) and ‘statsmodels’ (or an instance of StatsModelsInference)

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_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\}$$. 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)

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) )

score(Y, T, X=None, W=None)

Score the fitted CATE model on a new data set. Generates nuisance parameters for the new data set based on the fitted residual nuisance models created at fit time. It uses the mean prediction of the models fitted by the different crossfit folds. Then calculates the MSE of the final residual Y on residual T regression.

If model_final does not have a score method, then it raises an AttributeError

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 or None (Default=None)) – Features for each sample

• W (optional(n, d_w) matrix or None (Default=None)) – Controls for each sample

Returns

score – The MSE of the final CATE model on the new data.

Return type

float

summary(alpha=0.1, value=0, decimals=3, feat_name=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.

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

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 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

property model_cate

Get the fitted final CATE model.

Returns

model_cate – An instance of the model_final object that was fitted after calling fit which corresponds to the constant marginal CATE model.

Return type

object of type(model_final)

property models_t

Get the fitted models for E[T | X, W].

Returns

models_y – A list of instances of the model_y object. Each element corresponds to a crossfitting fold and is the model instance that was fitted for that training fold.

Return type

list of objects of type(model_t)

property models_y

Get the fitted models for E[Y | X, W].

Returns

models_y – A list of instances of the model_y object. Each element corresponds to a crossfitting fold and is the model instance that was fitted for that training fold.

Return type

list of objects of type(model_y)

class econml.dml.NonParamDMLCateEstimator(model_y, model_t, model_final, featurizer=None, discrete_treatment=False, n_splits=2, random_state=None)[source]

Bases: econml.dml._BaseDMLCateEstimator

The base class for non-parametric Double ML estimators, that can have arbitrary final ML models of the CATE. Works only for single-dimensional continuous treatment or for binary categorical treatment and uses the re-weighting trick, reducing the final CATE estimation to a weighted square loss minimization. The model_final parameter must support the sample_weight keyword argument at fit time.

Parameters
• model_y (estimator) – The estimator for fitting the response to the features. Must implement fit and predict methods. Must be a linear model for correctness when linear_first_stages is True.

• model_t (estimator) – The estimator for fitting the treatment to the features. Must implement fit and predict methods. Must be a linear model for correctness when linear_first_stages is True.

• model_final (estimator) – The estimator for fitting the response residuals to the treatment residuals. Must implement fit and predict methods. It can be an arbitrary scikit-learn regressor. The fit method must accept sample_weight as a keyword argument.

• featurizer (transformer) – The transformer used to featurize the raw features when fitting the final model. Must implement a fit_transform method.

• discrete_treatment (bool, optional (default is False)) – Whether the treatment values should be treated as categorical, rather than continuous, quantities

• n_splits (int, cross-validation generator or an iterable, optional (Default=2)) – Determines the cross-validation splitting strategy. Possible inputs for cv are:

• None, to use the default 3-fold cross-validation,

• integer, to specify the number of folds.

• CV splitter

• An iterable yielding (train, test) splits as arrays of indices.

For integer/None inputs, if the treatment is discrete StratifiedKFold is used, else, KFold is used (with a random shuffle in either case).

Unless an iterable is used, we call split(concat[W, X], T) to generate the splits. If all W, X are None, then we call split(ones((T.shape[0], 1)), T).

• random_state (int, RandomState instance or None, optional (default=None)) – If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

cate_feature_names(input_feature_names=None)

Get the output feature names.

Parameters

input_feature_names (list of strings of length X.shape[1] or None) – The names of the input features

Returns

out_feature_names – The names of the output features $$\phi(X)$$, i.e. the features with respect to which the final constant marginal CATE model is linear. It is the names of the features that are associated with each entry of the coef_() parameter. Not available when the featurizer is not None and does not have a method: get_feature_names(input_feature_names). Otherwise None is returned.

Return type

list of strings or None

const_marginal_effect(X=None)

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)

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)

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=0, T1=1)

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)) )

fit(Y, T, X=None, W=None, *, sample_weight=None, sample_var=None, inference=None)

Estimate the counterfactual model from data, i.e. estimates function $$\theta(\cdot)$$.

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 or None (Default=None)) – Features for each sample

• W (optional(n, d_w) matrix or None (Default=None)) – Controls for each sample

• sample_weight (optional(n,) vector or None (Default=None)) – Weights for each samples

• sample_var (optional(n,) vector or None (Default=None)) – Sample variance for each sample

• inference (string,:class:.Inference instance, or None) – Method for performing inference. This estimator supports ‘bootstrap’ (or an instance of:class:.BootstrapInference).

Returns

self

Return type

_RLearner instance

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\}$$. 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)

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) )

score(Y, T, X=None, W=None)

Score the fitted CATE model on a new data set. Generates nuisance parameters for the new data set based on the fitted residual nuisance models created at fit time. It uses the mean prediction of the models fitted by the different crossfit folds. Then calculates the MSE of the final residual Y on residual T regression.

If model_final does not have a score method, then it raises an AttributeError

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 or None (Default=None)) – Features for each sample

• W (optional(n, d_w) matrix or None (Default=None)) – Controls for each sample

Returns

score – The MSE of the final CATE model on the new data.

Return type

float

property model_cate

Get the fitted final CATE model.

Returns

model_cate – An instance of the model_final object that was fitted after calling fit which corresponds to the constant marginal CATE model.

Return type

object of type(model_final)

property models_t

Get the fitted models for E[T | X, W].

Returns

models_y – A list of instances of the model_y object. Each element corresponds to a crossfitting fold and is the model instance that was fitted for that training fold.

Return type

list of objects of type(model_t)

property models_y

Get the fitted models for E[Y | X, W].

Returns

models_y – A list of instances of the model_y object. Each element corresponds to a crossfitting fold and is the model instance that was fitted for that training fold.

Return type

list of objects of type(model_y)

class econml.dml.SparseLinearDMLCateEstimator(model_y=<econml.sklearn_extensions.linear_model.WeightedLassoCVWrapper object>, model_t='auto', alpha='auto', max_iter=1000, tol=0.0001, featurizer=None, fit_cate_intercept=True, linear_first_stages=True, discrete_treatment=False, n_splits=2, random_state=None)[source]

A specialized version of the Double ML estimator for the sparse linear case.

This estimator should be used when the features of heterogeneity are high-dimensional and the coefficients of the linear CATE function are sparse.

The last stage is an instance of the MultiOutputDebiasedLasso

Parameters
• model_y (estimator, optional (default is WeightedLassoCVWrapper()) --) The estimator for fitting the response to the features. Must implement fit and predict methods.

• model_t (estimator or ‘auto’, optional (default is ‘auto’)) – The estimator for fitting the treatment to the features. If estimator, it must implement fit and predict methods, and must be a linear model for correctness; If ‘auto’, LogisticRegressionCV will be applied for discrete treatment, and WeightedLassoCV/ WeightedMultiTaskLassoCV will be applied for continuous treatment.

• alpha (string | float, optional. Default=’auto’.) – CATE L1 regularization applied through the debiased lasso in the final model. ‘auto’ corresponds to a CV form of the MultiOutputDebiasedLasso.

• max_iter (int, optional, default=1000) – The maximum number of iterations in the Debiased Lasso

• tol (float, optional, default=1e-4) – The tolerance for the optimization: if the updates are smaller than tol, the optimization code checks the dual gap for optimality and continues until it is smaller than tol.

• featurizer (transformer, optional, default None) – Must support fit_transform and transform. Used to create composite features in the final CATE regression. It is ignored if X is None. The final CATE will be trained on the outcome of featurizer.fit_transform(X). If featurizer=None, then CATE is trained on X.

• fit_cate_intercept (bool, optional, default True) – Whether the linear CATE model should have a constant term.

• linear_first_stages (bool) – Whether the first stage models are linear (in which case we will expand the features passed to model_y accordingly)

• discrete_treatment (bool, optional (default is False)) – Whether the treatment values should be treated as categorical, rather than continuous, quantities

• n_splits (int, cross-validation generator or an iterable, optional (Default=2)) – Determines the cross-validation splitting strategy. Possible inputs for cv are:

• None, to use the default 3-fold cross-validation,

• integer, to specify the number of folds.

• CV splitter

• An iterable yielding (train, test) splits as arrays of indices.

For integer/None inputs, if the treatment is discrete StratifiedKFold is used, else, KFold is used (with a random shuffle in either case).

Unless an iterable is used, we call split(X,T) to generate the splits.

• random_state (int, RandomState instance or None, optional (default=None)) – If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

cate_feature_names(input_feature_names=None)

Get the output feature names.

Parameters

input_feature_names (list of strings of length X.shape[1] or None) – The names of the input features

Returns

out_feature_names – The names of the output features $$\phi(X)$$, i.e. the features with respect to which the final constant marginal CATE model is linear. It is the names of the features that are associated with each entry of the coef_() parameter. Not available when the featurizer is not None and does not have a method: get_feature_names(input_feature_names). Otherwise None is returned.

Return type

list of strings or None

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_())

const_marginal_effect(X=None)

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)

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)

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=0, T1=1)

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)) )

fit(Y, T, X=None, W=None, sample_weight=None, sample_var=None, inference=None)[source]

Estimate the counterfactual model from data, i.e. estimates functions τ(·,·,·), ∂τ(·,·).

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

• T ((n × dₜ) matrix or vector of length n) – Treatments for each sample

• X (optional (n × dₓ) matrix) – Features for each sample

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

• sample_weight (optional (n,) vector) – Weights for each row

• sample_var (optional (n, n_y) vector) – Variance of sample, in case it corresponds to summary of many samples. Currently not in use by this method but will be supported in a future release.

• inference (string, Inference instance, or None) – Method for performing inference. This estimator supports ‘bootstrap’ (or an instance of BootstrapInference) and ‘debiasedlasso’ (or an instance of LinearModelFinalInference)

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_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\}$$. 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)

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) )

score(Y, T, X=None, W=None)

Score the fitted CATE model on a new data set. Generates nuisance parameters for the new data set based on the fitted residual nuisance models created at fit time. It uses the mean prediction of the models fitted by the different crossfit folds. Then calculates the MSE of the final residual Y on residual T regression.

If model_final does not have a score method, then it raises an AttributeError

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 or None (Default=None)) – Features for each sample

• W (optional(n, d_w) matrix or None (Default=None)) – Controls for each sample

Returns

score – The MSE of the final CATE model on the new data.

Return type

float

summary(alpha=0.1, value=0, decimals=3, feat_name=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.

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

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 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

property model_cate

Get the fitted final CATE model.

Returns

model_cate – An instance of the model_final object that was fitted after calling fit which corresponds to the constant marginal CATE model.

Return type

object of type(model_final)

property models_t

Get the fitted models for E[T | X, W].

Returns

models_y – A list of instances of the model_y object. Each element corresponds to a crossfitting fold and is the model instance that was fitted for that training fold.

Return type

list of objects of type(model_t)

property models_y

Get the fitted models for E[Y | X, W].

Returns

models_y – A list of instances of the model_y object. Each element corresponds to a crossfitting fold and is the model instance that was fitted for that training fold.

Return type

list of objects of type(model_y)