Skip to content

Commit 682b8b2

Browse files
committed
Update learners.rst
1 parent cf4b687 commit 682b8b2

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

doc/guide/learners.rst

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,59 @@ In this case the tuning should be done externally and the parameters can then be
171171
172172
.. TODO: Also discuss other specification options like `tune_on_folds` or `scoring_methods`.
173173
174+
Evaluate learners
175+
#################
176+
177+
To compare different learners it is possible to evaluate the out-of-sample performance of each learner. The ``summary``
178+
already shows the root mean squared error (RMSE) for each learner and each corresponding repetition of cross-fitting (``n_rep`` argument).
179+
180+
To illustrate the parameter tuning, we work with the following example.
181+
182+
.. tabbed:: Python
183+
184+
.. ipython:: python
185+
186+
import doubleml as dml
187+
from doubleml.datasets import make_plr_CCDDHNR2018
188+
from sklearn.ensemble import RandomForestRegressor
189+
190+
np.random.seed(1234)
191+
ml_l = RandomForestRegressor()
192+
ml_m = RandomForestRegressor()
193+
data = make_plr_CCDDHNR2018(alpha=0.5, return_type='DataFrame')
194+
obj_dml_data = dml.DoubleMLData(data, 'y', 'd')
195+
dml_plr_obj = dml.DoubleMLPLR(obj_dml_data, ml_l, ml_m)
196+
dml_plr_obj.fit()
197+
print(dml_plr_obj)
198+
199+
The RMSEs of each learner are also stored in the ``rmses`` attribute.
200+
Further, the ``evaluate_learners()`` method is allows to evalute customized evaluation metrics as e.g. the mean absolute error.
201+
The default option is still the RMSE for evaluation.
202+
203+
.. tabbed:: Python
204+
205+
.. ipython:: python
206+
207+
print(dml_plr_obj.rmses)
208+
print(dml_plr_obj.evaluate_learners())
209+
210+
To evaluate a customized metric one hass to define a ``callable``. For some models (e.g. the IRM model) it is important that
211+
the metric can handle ``nan`` values as not all target values are known.
212+
213+
.. tabbed:: Python
214+
215+
.. ipython:: python
216+
217+
from sklearn.metrics import mean_absolute_error
218+
219+
def mae(y_true, y_pred):
220+
subset = np.logical_not(np.isnan(y_true))
221+
return mean_absolute_error(y_true[subset], y_pred[subset])
222+
223+
dml_plr_obj.evaluate_learners(learners=['ml_l'], metric=mae)
224+
225+
A more detailed notebook on the choice of learners is available in the :ref:`example gallery <examplegallery>`.
226+
174227
.. _learners_r:
175228

176229
R: Learners and hyperparameters

0 commit comments

Comments
 (0)