xgboost中的访问训练和评估错误 [英] Access train and evaluation error in xgboost

查看:125
本文介绍了xgboost中的访问训练和评估错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用python xgboost支持.有没有一种方法可以在每个训练时期获得训练和验证错误?我在文档

I started using python xgboost backage. Is there a way to get training and validation errors at each training epoch? I can't find one in the documentation

已经训练了一个简单的模型并获得了输出:

Have trained a simple model and got output:

[09:17:37] src/tree/updater_prune.cc:74:树修剪结束,有1个根, 124个额外的节点,0个修剪的节点,max_depth = 6

[09:17:37] src/tree/updater_prune.cc:74: tree pruning end, 1 roots, 124 extra nodes, 0 pruned nodes, max_depth=6

[0]评估均方根:0.407474火车均方根:0.346349 [09:17:37] src/tree/updater_prune.cc:74:树修剪结束,有1个根,额外有116个 节点,0个修剪的节点,max_depth = 6

[0] eval-rmse:0.407474 train-rmse:0.346349 [09:17:37] src/tree/updater_prune.cc:74: tree pruning end, 1 roots, 116 extra nodes, 0 pruned nodes, max_depth=6

1 eval-rmse:0.410902 train-rmse: 0.339925 [09:17:38] src/tree/updater_prune.cc:74:树修剪结束,有1个根,额外有124个 节点,0个修剪的节点,max_depth = 6

1 eval-rmse:0.410902 train-rmse:0.339925 [09:17:38] src/tree/updater_prune.cc:74: tree pruning end, 1 roots, 124 extra nodes, 0 pruned nodes, max_depth=6

[2]评估均方根:0.413563火车均方根:0.335941 [09:17:38] src/tree/updater_prune.cc:74:修剪树结束,1个根,额外126个 节点,0个修剪的节点,max_depth = 6

[2] eval-rmse:0.413563 train-rmse:0.335941 [09:17:38] src/tree/updater_prune.cc:74: tree pruning end, 1 roots, 126 extra nodes, 0 pruned nodes, max_depth=6

[3]评估均方根:0.418412火车均方根:0.333071 [09:17:38] src/tree/updater_prune.cc:74:树修剪结束,1个根,额外114个 节点,0个修剪的节点,max_depth = 6

[3] eval-rmse:0.418412 train-rmse:0.333071 [09:17:38] src/tree/updater_prune.cc:74: tree pruning end, 1 roots, 114 extra nodes, 0 pruned nodes, max_depth=6

但是我需要在代码中进一步传递这些eval-rmsetrain-rmse,或者至少绘制这些曲线.

However I need to pass these eval-rmse and train-rmse further in code or at least plot these curves.

推荐答案

保存中间结果的一种方法是将evals_result参数传递给xgb.train方法.

One way to save your intermediate results is by passing evals_result argument to xgb.train method.

假设您已经创建了XGB格式的traineval矩阵,并为XGBoost初始化了一些参数params(在我的情况下为params = {'max_depth':2, 'eta':1, 'silent':1, 'objective':'binary:logistic' }).

Let's say you have created a train and an eval matrix in XGB format, and have initialized some parameters params for XGBoost (In my case, params = {'max_depth':2, 'eta':1, 'silent':1, 'objective':'binary:logistic' }).

  1. 创建一个空的字典

  1. Create an empty dict

progress = dict()

创建一个监视列表,(考虑到您正在打印train-rmse,我想您已经有了它)

Create a watchlist, (I guess you already have it given that you are printing train-rmse)

watchlist = [(train,'train-rmse'), (eval, 'eval-rmse')]

将这些传递给xgb.train

bst = xgb.train(param, train, 10, watchlist, evals_result=progress)

在迭代结束时,progress词典将包含所需的训练/验证错误

At the end of iteration, the progress dictionary will contain the desired train/validation errors

> print progress
{'train-rmse': {'error': ['0.50000', ....]}, 'eval-rmse': { 'error': ['0.5000',....]}}

这篇关于xgboost中的访问训练和评估错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆