Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions econml/_ortho_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ def predict(self, X, y, W=None):
X, y,W=y, Z=None)

>>> nuisance
(array([-1.105728... , -1.537566..., -2.451827... , ..., 1.106287...,
-1.829662..., -1.782273...], shape=(5000,)),)
(array([-1.1057289 , -1.53756637, -2.4518278 , ..., 1.10628792,
-1.82966233, -1.78227335], shape=(5000,)),)
>>> model_list
[<Wrapper object at 0x...>, <Wrapper object at 0x...>]
>>> fitted_inds
Expand Down Expand Up @@ -475,19 +475,19 @@ def _gen_ortho_learner_model_final(self):
est.fit(y, X[:, 0], W=X[:, 1:])

>>> est.score_
np.float64(0.00756830...)
np.float64(0.00756830)
>>> est.const_marginal_effect()
np.float64(1.02364992...)
np.float64(1.02364992)
>>> est.effect()
array([1.023649...])
array([1.023649])
>>> est.effect(T0=0, T1=10)
array([10.236499...])
array([10.236499])
>>> est.score(y, X[:, 0], W=X[:, 1:])
np.float64(0.00727995...)
np.float64(0.00727995)
>>> est.ortho_learner_model_final_.model
LinearRegression(fit_intercept=False)
>>> est.ortho_learner_model_final_.model.coef_
array([1.023649...])
array([1.023649])

The following example shows how to do double machine learning with discrete treatments, using
the _OrthoLearner:
Expand Down Expand Up @@ -533,15 +533,15 @@ def _gen_ortho_learner_model_final(self):
est.fit(y, T, W=W)

>>> est.score_
np.float64(0.00672978...)
np.float64(0.00672978)
>>> est.const_marginal_effect()
array([[1.008402...]])
array([[1.008402]])
>>> est.effect()
array([1.008402...])
array([1.008402])
>>> est.score(y, T, W=W)
np.float64(0.00310431...)
np.float64(0.00310431)
>>> est.ortho_learner_model_final_.model.coef_[0]
np.float64(1.00840240...)
np.float64(1.00840240)

Attributes
----------
Expand Down
10 changes: 5 additions & 5 deletions econml/dml/_rlearner.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,17 +332,17 @@ def _gen_rlearner_model_final(self):
est.fit(y, X[:, 0], X=np.ones((X.shape[0], 1)), W=X[:, 1:])

>>> est.const_marginal_effect(np.ones((1,1)))
array([0.999631...])
array([0.999631])
>>> est.effect(np.ones((1,1)), T0=0, T1=10)
array([9.996314...])
array([9.996314])
>>> est.score(y, X[:, 0], X=np.ones((X.shape[0], 1)), W=X[:, 1:])
9.73638006...e-05
9.73638006e-05
>>> est.rlearner_model_final_.model
LinearRegression(fit_intercept=False)
>>> est.rlearner_model_final_.model.coef_
array([0.999631...])
array([0.999631])
>>> est.score_
9.82623204...e-05
9.82623204e-05
>>> [mdl._model for mdls in est.models_y for mdl in mdls]
[LinearRegression(), LinearRegression()]
>>> [mdl._model for mdls in est.models_t for mdl in mdls]
Expand Down
6 changes: 3 additions & 3 deletions econml/dml/causal_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,10 @@ class CausalForestDML(_BaseDML):
est.fit(y, T, X=X, W=None)

>>> est.effect(X[:3])
array([0.62769..., 1.64575..., 0.68497...])
array([0.62769, 1.64575, 0.68497])
>>> est.effect_interval(X[:3])
(array([0.18798..., 1.17144..., 0.10788...]),
array([1.06739..., 2.12006..., 1.26205...]))
(array([0.18798, 1.17144, 0.10788]),
array([1.06739, 2.12006, 1.26205]))

Attributes
----------
Expand Down
52 changes: 26 additions & 26 deletions econml/dml/dml.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,19 +500,19 @@ class takes as input the parameter `model_t`, which is an arbitrary scikit-learn
est.fit(y, T, X=X, W=None)

>>> est.effect(X[:3])
array([0.63382..., 1.78225..., 0.71859...])
array([0.63382, 1.78225, 0.71859])
>>> est.effect_interval(X[:3])
(array([0.27937..., 1.27619..., 0.42091...]),
array([0.98827... , 2.28831..., 1.01628...]))
(array([0.27937, 1.27619, 0.42091]),
array([0.98827 , 2.28831, 1.01628]))
>>> est.coef_
array([ 0.42857..., 0.04488..., -0.03317..., 0.02258..., -0.14875...])
array([ 0.42857, 0.04488, -0.03317, 0.02258, -0.14875])
>>> est.coef__interval()
(array([ 0.25179..., -0.10558..., -0.16723... , -0.11916..., -0.28759...]),
array([ 0.60535..., 0.19536..., 0.10088..., 0.16434..., -0.00990...]))
(array([ 0.25179, -0.10558, -0.16723 , -0.11916, -0.28759]),
array([ 0.60535, 0.19536, 0.10088, 0.16434, -0.00990]))
>>> est.intercept_
1.01166...
1.01166
>>> est.intercept__interval()
(0.87125..., 1.15207...)
(0.87125, 1.15207)
"""

def __init__(self, *,
Expand Down Expand Up @@ -854,19 +854,19 @@ class LinearDML(StatsModelsCateEstimatorMixin, DML):
est.fit(y, T, X=X, W=None)

>>> est.effect(X[:3])
array([0.49976..., 1.91673..., 0.70800...])
array([0.49976, 1.91673, 0.70800])
>>> est.effect_interval(X[:3])
(array([0.15122..., 1.40182..., 0.40956...]),
array([0.84831..., 2.43164..., 1.00645...]))
(array([0.15122, 1.40182, 0.40956]),
array([0.84831, 2.43164, 1.00645]))
>>> est.coef_
array([ 0.48825..., 0.00104..., 0.00244..., 0.02217..., -0.08472...])
array([ 0.48825, 0.00104, 0.00244, 0.02217, -0.08472])
>>> est.coef__interval()
(array([ 0.30470... , -0.13905..., -0.12789..., -0.11513..., -0.22506...]),
array([0.67180..., 0.14114..., 0.13278..., 0.15949..., 0.05561...]))
(array([ 0.30470 , -0.13905, -0.12789, -0.11513, -0.22506]),
array([0.67180, 0.14114, 0.13278, 0.15949, 0.05561]))
>>> est.intercept_
1.01248...
1.01248
>>> est.intercept__interval()
(0.87481..., 1.15015...)
(0.87481, 1.15015)
"""

def __init__(self, *,
Expand Down Expand Up @@ -1115,19 +1115,19 @@ class SparseLinearDML(DebiasedLassoCateEstimatorMixin, DML):
est.fit(y, T, X=X, W=None)

>>> est.effect(X[:3])
array([0.50083..., 1.91668..., 0.70388...])
array([0.50083, 1.91668, 0.70388])
>>> est.effect_interval(X[:3])
(array([0.14616..., 1.40370..., 0.40675...]),
array([0.85550..., 2.42966..., 1.00101...]))
(array([0.14616, 1.40370, 0.40675]),
array([0.85550, 2.42966, 1.00101]))
>>> est.coef_
array([ 0.49123..., 0.00493... , 0.00007..., 0.02302..., -0.08484...])
array([ 0.49123452, 0.0049377 , 0.00007303, 0.02302108, -0.08484665])
>>> est.coef__interval()
(array([ 0.31323..., -0.13850..., -0.13720..., -0.11141..., -0.22962...]),
array([0.66923..., 0.14837..., 0.13735..., 0.15745..., 0.05992...]))
(array([ 0.31323, -0.13850, -0.13720, -0.11141, -0.22962]),
array([0.66923, 0.14837, 0.13735, 0.15745, 0.05992]))
>>> est.intercept_
1.01477...
1.01477
>>> est.intercept__interval()
(0.87621..., 1.15333...)
(0.87621, 1.15333)
"""

def __init__(self, *,
Expand Down Expand Up @@ -1373,7 +1373,7 @@ class KernelDML(DML):
est.fit(y, T, X=X, W=None)

>>> est.effect(X[:3])
array([0.63042..., 1.86101..., 0.74220...])
array([0.63042, 1.86101, 0.74220])
"""

def __init__(self, model_y='auto', model_t='auto',
Expand Down Expand Up @@ -1597,7 +1597,7 @@ class NonParamDML(_BaseDML):
est.fit(y, T, X=X, W=None)

>>> est.effect(X[:3])
array([0.35318..., 1.28760..., 0.83506...])
array([0.35318, 1.28760, 0.83506])
"""

def __init__(self, *,
Expand Down
58 changes: 29 additions & 29 deletions econml/dr/_drlearner.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,18 +520,18 @@ class takes as input the parameter ``model_regressor``, which is an arbitrary sc
est.fit(y, T, X=X, W=None)

>>> est.const_marginal_effect(X[:2])
array([[0.516888..., 0.995747...],
[0.356386..., 0.671889...]])
array([[0.516888, 0.995747],
[0.356386, 0.671889]])
>>> est.effect(X[:2], T0=0, T1=1)
array([0.516888..., 0.356386...])
array([0.516888, 0.356386])
>>> est.score_
np.float64(2.845660...)
np.float64(2.845660)
>>> est.score(y, T, X=X)
np.float64(1.062668...)
np.float64(1.062668)
>>> est.model_cate(T=1).coef_
array([ 0.447146..., -0.001025..., 0.018984...])
array([ 0.447146, -0.001025, 0.018984])
>>> est.model_cate(T=2).coef_
array([ 0.925064..., -0.012351..., 0.033480...])
array([ 0.925064, -0.012351, 0.033480])
>>> est.cate_feature_names()
['X0', 'X1', 'X2']

Expand All @@ -555,19 +555,19 @@ class takes as input the parameter ``model_regressor``, which is an arbitrary sc
est.fit(y, T, X=X, W=None)

>>> est.score_
np.float64(1.73...)
np.float64(1.73)
>>> est.const_marginal_effect(X[:3])
array([[0.68..., 1.10...],
[0.56..., 0.79... ],
[0.34..., 0.10... ]])
array([[0.68151771, 1.10936267],
[0.56679957, 0.7941794 ],
[0.34171272, 0.1045798 ]])
>>> est.model_cate(T=2).coef_
array([0.74..., 0. , 0. ])
array([0.74925162, 0. , 0. ])
>>> est.model_cate(T=2).intercept_
np.float64(1.9...)
np.float64(1.9227731541272008)
>>> est.model_cate(T=1).coef_
array([0.24..., 0.00..., 0. ])
array([0.24572861, 0.00720134, 0. ])
>>> est.model_cate(T=1).intercept_
np.float64(0.94...)
np.float64(0.94)

Attributes
----------
Expand Down Expand Up @@ -1245,19 +1245,19 @@ class LinearDRLearner(StatsModelsCateEstimatorDiscreteMixin, DRLearner):
est.fit(y, T, X=X, W=None)

>>> est.effect(X[:3])
array([ 0.432365..., 0.359694..., -0.085428...])
array([ 0.432365, 0.359694, -0.085428])
>>> est.effect_interval(X[:3])
(array([ 0.084048..., -0.177951... , -0.734747...]),
array([0.780683..., 0.897341..., 0.563889...]))
(array([ 0.084048, -0.177951 , -0.734747]),
array([0.780683, 0.897341, 0.563889]))
>>> est.coef_(T=1)
array([ 0.450666..., -0.008821..., 0.075271...])
array([ 0.450666, -0.008821, 0.075271])
>>> est.coef__interval(T=1)
(array([ 0.156245..., -0.252216..., -0.159709...]),
array([0.745086..., 0.234572..., 0.310252...]))
(array([ 0.156245, -0.252216, -0.159709]),
array([0.745086, 0.234572, 0.310252]))
>>> est.intercept_(T=1)
np.float64(0.909121...)
np.float64(0.909121)
>>> est.intercept__interval(T=1)
(np.float64(0.668518...), np.float64(1.149723...))
(np.float64(0.668518), np.float64(1.149723))

Attributes
----------
Expand Down Expand Up @@ -1582,17 +1582,17 @@ class SparseLinearDRLearner(DebiasedLassoCateEstimatorDiscreteMixin, DRLearner):
est.fit(y, T, X=X, W=None)

>>> est.effect(X[:3])
array([ 0.43..., 0.35..., -0.08...])
array([ 0.43296409, 0.35952902, -0.08460643])
>>> est.effect_interval(X[:3])
(array([-0.01..., -0.26..., -0.81...]), array([0.87..., 0.98..., 0.65...]))
(array([-0.01363264, -0.26369244, -0.81995536]), array([0.87956083, 0.98275048, 0.65074251]))
>>> est.coef_(T=1)
array([ 0.44..., -0.00..., 0.07...])
array([ 0.44991911, -0.00881137, 0.07449517])
>>> est.coef__interval(T=1)
(array([ 0.19... , -0.24..., -0.17...]), array([0.70..., 0.22..., 0.32...]))
(array([ 0.1972161 , -0.24730627, -0.17104381]), array([0.70262212, 0.22968353, 0.32003415]))
>>> est.intercept_(T=1)
np.float64(0.90...)
np.float64(0.9091174878444385)
>>> est.intercept__interval(T=1)
(np.float64(0.66...), np.float64(1.14...))
(np.float64(0.6687723462464192), np.float64(1.1494626294424575))

Attributes
----------
Expand Down
6 changes: 3 additions & 3 deletions econml/grf/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ class RegressionForest(BaseGRF):

np.set_printoptions(suppress=True)
np.random.seed(123)
X, y = make_regression(n_samples=1000, n_features=4, n_informative=2,
X, y = make_regression(n_samples=1000, n_features=4, n_informative=4,
random_state=0, shuffle=False)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.5)
regr = RegressionForest(max_depth=None, random_state=0,
Expand All @@ -958,9 +958,9 @@ class RegressionForest(BaseGRF):
>>> regr.fit(X_train, y_train)
RegressionForest(n_estimators=1000, random_state=0)
>>> regr.feature_importances_
array([0.88..., 0.11..., 0.00..., 0.00...])
array([0.2869952 , 0.03651571, 0.59767877, 0.07881031])
>>> regr.predict(np.ones((1, 4)), interval=True, alpha=.05)
(array([[121.0...]]), array([[103.6...]]), array([[138.3...]]))
(array([[194.5075591]]), array([[159.10510002]]), array([[229.91001818]]))

References
----------
Expand Down
24 changes: 12 additions & 12 deletions econml/iv/dml/_dml.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,19 @@ def true_heterogeneity_function(X):
est.fit(Y=y, T=T, Z=Z, X=X)

>>> est.effect(X[:3])
array([-4.28039..., 6.02945..., -2.86845...])
array([-4.28039, 6.02945, -2.86845])
>>> est.effect_interval(X[:3])
(array([-7.20723... , 1.75413..., -5.20891...]),
array([-1.35355..., 10.30477..., -0.52799...]))
(array([-7.20723 , 1.75413, -5.20891]),
array([-1.35355, 10.30477, -0.52799]))
>>> est.coef_
array([ 4.51656..., 0.78512..., 0.23706..., 0.24127..., -0.47167...])
array([ 4.51656, 0.78512, 0.23706, 0.24127, -0.47167])
>>> est.coef__interval()
(array([ 3.15599..., -0.35785..., -0.89798..., -0.90529..., -1.62444...]),
array([5.87712..., 1.92810..., 1.37211..., 1.38783..., 0.68110...]))
(array([ 3.15599, -0.35785, -0.89798, -0.90529, -1.62444]),
array([5.87712, 1.92810, 1.37211, 1.38783, 0.68110]))
>>> est.intercept_
-0.13668...
-0.13668
>>> est.intercept__interval()
(-1.27031..., 0.99694...)
(-1.27031, 0.99694)
"""

def __init__(self, *,
Expand Down Expand Up @@ -1143,11 +1143,11 @@ def true_heterogeneity_function(X):
est.fit(Y=y, T=T, Z=Z, X=X)

>>> est.effect(X[:3])
array([-3.83456..., 5.32010..., -2.78127...])
array([-3.83456, 5.32010, -2.78127])
>>> est.coef_
array([ 4.03977..., 0.89360..., 0.12047..., 0.37971..., -0.66072...])
array([ 4.03977, 0.89360, 0.12047, 0.37971, -0.66072])
>>> est.intercept_
-0.18452...
-0.18452

"""

Expand Down Expand Up @@ -1536,7 +1536,7 @@ def true_heterogeneity_function(X):
est.fit(Y=y, T=T, Z=Z, X=X)

>>> est.effect(X[:3])
array([-5.98684..., 9.03751..., -3.56817...])
array([-5.98684, 9.03751, -3.56817])

"""

Expand Down
Loading
Loading