.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "python/examples/evals_result.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_python_examples_evals_result.py: This script demonstrate how to access the eval metrics ====================================================== .. GENERATED FROM PYTHON SOURCE LINES 5-44 .. code-block:: Python import os import xgboost as xgb CURRENT_DIR = os.path.dirname(__file__) dtrain = xgb.DMatrix( os.path.join(CURRENT_DIR, "../data/agaricus.txt.train?format=libsvm") ) dtest = xgb.DMatrix( os.path.join(CURRENT_DIR, "../data/agaricus.txt.test?format=libsvm") ) param = [ ("max_depth", 2), ("objective", "binary:logistic"), ("eval_metric", "logloss"), ("eval_metric", "error"), ] num_round = 2 watchlist = [(dtest, "eval"), (dtrain, "train")] evals_result = {} bst = xgb.train(param, dtrain, num_round, watchlist, evals_result=evals_result) print("Access logloss metric directly from evals_result:") print(evals_result["eval"]["logloss"]) print("") print("Access metrics through a loop:") for e_name, e_mtrs in evals_result.items(): print("- {}".format(e_name)) for e_mtr_name, e_mtr_vals in e_mtrs.items(): print(" - {}".format(e_mtr_name)) print(" - {}".format(e_mtr_vals)) print("") print("Access complete dictionary:") print(evals_result) .. _sphx_glr_download_python_examples_evals_result.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: evals_result.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: evals_result.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: evals_result.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_