如何保存和保存加载xgboost模型? [英] How to save & load xgboost model?
问题描述
在 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
我的问题在后面.
-
save_model
&和有什么区别?dump_model
? - 保存
'0001.model'
和'dump.raw.txt','featmap.txt'
有什么区别? - 为什么要加载的模型名称
model.bin
与要保存的名称0001.model
不同? - 假设我训练了两个模型:
model_A
和model_B
.我想保存两个模型以备将来使用.哪个save
&我应该使用load
函数吗?您能帮忙说明清楚的过程吗?
- What's the difference between
save_model
&dump_model
? - What's the difference between saving
'0001.model'
and'dump.raw.txt','featmap.txt'
? - Why the model name for loading
model.bin
is different from the name to be saved0001.model
? - Suppose that I trained two models:
model_A
andmodel_B
. I wanted to save both models for future use. Whichsave
&load
function should I use? Could you help show the clear process?
推荐答案
函数save_model
和dump_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屋!