如何保存和保存加载xgboost模型? [英] How to save & load xgboost model?

查看:3472
本文介绍了如何保存和保存加载xgboost模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XGBoost指南的链接上:

训练后,可以保存模型.

After training, the model can be saved.

bst.save_model('0001.model')

模型及其特征图也可以转储到文本文件中.

The model and its feature map can also be dumped to a text file.

# dump model
bst.dump_model('dump.raw.txt')
# dump model with feature map
bst.dump_model('dump.raw.txt', 'featmap.txt')

保存的模型可以按以下方式加载:

A saved model can be loaded as follows:

bst = xgb.Booster({'nthread': 4})  # init model
bst.load_model('model.bin')  # load data

我的问题在后面.

  1. save_model&和有什么区别? dump_model?
  2. 保存'0001.model''dump.raw.txt','featmap.txt'有什么区别?
  3. 为什么要加载的模型名称model.bin与要保存的名称0001.model不同?
  4. 假设我训练了两个模型:model_Amodel_B.我想保存两个模型以备将来使用.哪个save&我应该使用load函数吗?您能帮忙说明清楚的过程吗?
  1. What's the difference between save_model & dump_model?
  2. What's the difference between saving '0001.model' and 'dump.raw.txt','featmap.txt'?
  3. Why the model name for loading model.bin is different from the name to be saved 0001.model?
  4. Suppose that I trained two models: model_A and model_B. I wanted to save both models for future use. Which save & load function should I use? Could you help show the clear process?

推荐答案

函数save_modeldump_model都保存模型,不同之处在于,在dump_model中可以保存要素名称并以文本格式保存树.

Both functions save_model and dump_model save the model, the difference is that in dump_model you can save feature name and save tree in text format.

load_model将与save_model中的模型一起使用.例如,dump_model中的模型可以与 xgbfi 一起使用.

The load_model will work with model from save_model. The model from dump_model can be used for example with xgbfi.

在加载模型期间,您需要指定保存模型的路径.在示例bst.load_model("model.bin")中,模型是从文件model.bin中加载的-它只是具有模型的文件的名称.祝你好运!

During loading the model, you need to specify the path where your models is saved. In the example bst.load_model("model.bin") model is loaded from file model.bin - it is just a name of file with model. Good luck!

这篇关于如何保存和保存加载xgboost模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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