推断

Bootstrap 推断

通过传递 inference='bootstrap'inference=BootstrapInference(n_bootstrap_samples=100, n_jobs=-1),每个估计器都可以提供基于 bootstrap 的置信区间(参见 BootstrapInference)。这些区间是通过在带替换的 bootstrap 子样本上训练原始估计器的多个版本来计算的。然后根据多个副本中估计分布的分位数来计算区间。有关更多详细信息,另请参阅 BootstrapEstimator

例如

from econml.dml import NonParamDML
from sklearn.ensemble import RandomForestRegressor
est = NonParamDML(model_y=RandomForestRegressor(n_estimators=10, min_samples_leaf=10),
                            model_t=RandomForestRegressor(n_estimators=10, min_samples_leaf=10),
                            model_final=RandomForestRegressor(n_estimators=10, min_samples_leaf=10))
est.fit(y, t, X=X, W=W, inference='bootstrap')
point = est.const_marginal_effect(X)
lb, ub = est.const_marginal_effect_interval(X, alpha=0.05)

OLS 推断

对于最终阶段 CATE 估计基于普通最小二乘回归的估计器,我们默认提供基于正态性的置信区间(保留设置 inference='auto' 不变),或者通过显式设置 inference='statsmodels'。或者,根据估计器,可以通过 inference=StatsModelsInference(cov_type='HC1)inference=StatsModelsInferenceDiscrete(cov_type='HC1) 来改变协方差类型计算。有关更多详细信息,请参阅 StatsModelsInferenceStatsModelsInferenceDiscrete。例如,这适用于 LinearDMLLinearDRLearner

from econml.dml import LinearDML
from sklearn.ensemble import RandomForestRegressor
est = LinearDML(model_y=RandomForestRegressor(n_estimators=10, min_samples_leaf=10),
                             model_t=RandomForestRegressor(n_estimators=10, min_samples_leaf=10))
est.fit(y, t, X=X, W=W)
point = est.const_marginal_effect(X)
lb, ub = est.const_marginal_effect_interval(X, alpha=0.05)
from econml.dr import LinearDRLearner
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
est = LinearDRLearner(model_regression=RandomForestRegressor(n_estimators=10, min_samples_leaf=10),
                      model_propensity=RandomForestClassifier(n_estimators=10, min_samples_leaf=10))
est.fit(y, t, X=X, W=W)
point = est.effect(X)
lb, ub = est.effect_interval(X, alpha=0.05)

此推断是通过我们将 StatsModelsLinearRegression 扩展到 scikit-learn 的 LinearRegression 来实现的。

去偏 Lasso 推断

对于最终阶段 CATE 估计基于具有稀疏性约束的高维线性模型的估计器,我们提供使用去偏 lasso 技术的置信区间。例如,这适用于 SparseLinearDMLSparseLinearDRLearner。您可以默认启用这些区间(保留设置 inference='auto' 不变),或者通过显式设置 inference='debiasedlasso',例如。

from econml.dml import SparseLinearDML
from sklearn.ensemble import RandomForestRegressor
est = SparseLinearDML(model_y=RandomForestRegressor(n_estimators=10, min_samples_leaf=10),
                                   model_t=RandomForestRegressor(n_estimators=10, min_samples_leaf=10))
est.fit(y, t, X=X, W=W)
point = est.const_marginal_effect(X)
lb, ub = est.const_marginal_effect_interval(X, alpha=0.05)
from econml.dr import SparseLinearDRLearner
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
est = SparseLinearDRLearner(model_regression=RandomForestRegressor(n_estimators=10, min_samples_leaf=10),
                            model_propensity=RandomForestClassifier(n_estimators=10, min_samples_leaf=10))
est.fit(y, t, X=X, W=W)
point = est.effect(X)
lb, ub = est.effect_interval(X, alpha=0.05)

此推断是通过我们实现的 DebiasedLasso 扩展到 scikit-learn 的 Lasso 来实现的。

二次抽样诚实森林推断

对于最终阶段 CATE 估计是基于随机森林的非参数模型的估计器,我们通过 little bags 的 bootstrap 方法(参见 [Athey2019])提供置信区间,用于估计诚实随机森林的不确定性。例如,这适用于 CausalForestDMLForestDRLearner。通过将推断设置保留为默认值 inference='auto' 或显式设置 inference='blb' 来启用这些区间,例如。

from econml.dml import CausalForestDML
from sklearn.ensemble import RandomForestRegressor
est = CausalForestDML(model_y=RandomForestRegressor(n_estimators=10, min_samples_leaf=10),
                      model_t=RandomForestRegressor(n_estimators=10, min_samples_leaf=10))
est.fit(y, t, X=X, W=W)
point = est.const_marginal_effect(X)
lb, ub = est.const_marginal_effect_interval(X, alpha=0.05)
from econml.dr import ForestDRLearner
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
est = ForestDRLearner(model_regression=RandomForestRegressor(n_estimators=10, min_samples_leaf=10),
                      model_propensity=RandomForestClassifier(n_estimators=10, min_samples_leaf=10))
est.fit(y, t, X=X, W=W)
point = est.effect(X)
lb, ub = est.effect_interval(X, alpha=0.05)

此推断是通过我们实现的 RegressionForest 扩展到 scikit-learn 的 RandomForestRegressor 来实现的。

OrthoForest 小袋 Bootstrap 推断

对于正交随机森林估计器(参见 DMLOrthoForest, DROrthoForest),我们通过 little bags 的 bootstrap 方法([Athey2019])提供构建的置信区间。这种技术非常适合估计 OrthoForest 估计器所基于的诚实因果森林的不确定性。通过将推断设置保留为默认值 inference='auto' 或显式设置 inference='blb' 来启用这些区间,例如。

from econml.orf import DMLOrthoForest
from econml.sklearn_extensions.linear_model import WeightedLasso
est = DMLOrthoForest(n_trees=10,
                     min_leaf_size=3,
                     model_T=WeightedLasso(alpha=0.01),
                     model_Y=WeightedLasso(alpha=0.01))
est.fit(y, t, X=X, W=W)
point = est.const_marginal_effect(X)
lb, ub = est.const_marginal_effect_interval(X, alpha=0.05)