XGB模型训练报错 terminate called after throwing an instance of ‘std::bad_alloc‘ what()
Posted Alex_996
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了XGB模型训练报错 terminate called after throwing an instance of ‘std::bad_alloc‘ what()相关的知识,希望对你有一定的参考价值。
背景:需要做XGB模型增量训练,但是因为一些原因没有得到原来的XGB模型,只有dump文件。
XGB模型的dump文件是它的树结构存储为一个相对人类好理解的模型文件,但并不能被重新加载进XGB进行增量训练。
嗯,说是那么说,我寻思试一下,看看最新版的XGB有没有增加这个功能,只载入dump文件就可以进行XGB增量训练。
一跑起来没报错,我寻思可以呢。
一开始加载数据啥的都没问题,但是在训练的时候报错:terminate called after throwing an instance of 'std::bad_alloc' what():
,还把环境整崩了。
搜了一下,都说这是内存炸了导致的报错,但是我看了一下监控,内存完全没占满。
到这我还一直以为可能是我训练数据太大,或者是后台起的训练进程太多才导致的,完全没想过是不是dump文件的问题。
是在解决不了了,去洗了个澡,突然间就想到了,可能是dump文件的问题。
实验了一下,果然是,XGB模型增量训练只能在save_model
保存的模型文件上训练,不能在dump_model
的dump文件上训练,它不报解析错误反而报了一个内存错误。
实验代码:
import pandas as pd
import xgboost as xgb
import matplotlib.pyplot as plt
from xgboost import plot_tree
from xgboost import XGBClassifier
data = pd.read_csv("../input/default-of-credit-card-clients-dataset/UCI_Credit_Card.csv")
X = data.iloc[:,1:6]
y = data.iloc[:,24]
data = xgb.DMatrix(X, y)
xgb_params =
model = xgb.train(xgb_params, data)
print(model.get_dump())
model.save_model("model.pickle")
model.dump_model("model.dump")
xgb_params = 'process_type':'update', 'updater':'refresh', 'refresh_leaf':True
model_new = xgb.train(xgb_params, data, xgb_model="./model.pickle")
xgb_params = 'process_type':'update', 'updater':'refresh', 'refresh_leaf':True
model_new = xgb.train(xgb_params, data, xgb_model="./model.dump") # 报错
以上是关于XGB模型训练报错 terminate called after throwing an instance of ‘std::bad_alloc‘ what()的主要内容,如果未能解决你的问题,请参考以下文章
C++11多线程运行报错:terminate called without an active exception(没有join或detach子线程)
C++11多线程运行报错:terminate called without an active exception(没有join或detach子线程)
gcc报错:terminate called after throwing an instance of ‘std::regex_error‘ what(): regex
gcc报错:terminate called after throwing an instance of ‘std::regex_error‘ what(): regex
gcc报错:terminate called after throwing an instance of ‘std::regex_error‘ what(): regex
gcc报错:terminate called after throwing an instance of ‘std::regex_error‘ what(): regex