Note

Go to the endto download the full example code.

This script demonstrate how to access the eval metrics

importosfromtypingimportAny,DictimportxgboostasxgbCURRENT_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=2watchlist=[(dtest,"eval"),(dtrain,"train")]evals_result:Dict[str,Any]={}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:")fore_name,e_mtrsinevals_result.items():print("-{}".format(e_name))fore_mtr_name,e_mtr_valsine_mtrs.items():print("   -{}".format(e_mtr_name))print("      -{}".format(e_mtr_vals))print("")print("Access complete dictionary:")print(evals_result)

Gallery generated by Sphinx-Gallery