gpt4 book ai didi

python - 如何修复 'DMatrix/Booster has not been intialized or has already been disposed ' 错误

转载 作者:行者123 更新时间:2023-12-05 07:23:04 34 4
gpt4 key购买 nike

我训练了一个 xgboost 模型并保存了它。然后我将它复制到我的另一个系统,通过以下代码预测结果。

python 3.7,xgboost 0.8, conda

如果我从 csv 文件加载数据,相同的模型文件也可以工作。

try:
d_input = xgb.DMatrix([].append(input_vector))
xgb_model = xgb.Booster({'nthread': 4})
xgb_model.load_model('./models/xgboost.model')
print("Load model successfully.")
print(xgb_model)
docs[i].weight = xgb_model.predict(d_input)
except Exception as fail_xgb:
print(fail_xgb)

错误信息是:

Load model successfully.

<xgboost.core.Booster object at 0x1a1e72d4a8>
b'[11:51:46] src/c_api/c_api.cc:817: DMatrix/Booster has not been intialized or has already been disposed.\n\nStack trace returned 5 entries:\n[bt] (0) 0 libxgboost.dylib 0x0000001a1dfe7181 dmlc::StackTrace() + 305\n[bt] (1) 1 libxgboost.dylib 0x0000001a1dfe6f0f dmlc::LogMessageFatal::~LogMessageFatal() + 47\n[bt] (2) 2 libxgboost.dylib 0x0000001a1e0007c3 XGDMatrixNumCol + 99\n[bt] (3) 3 libffi.6.dylib 0x000000010b6e6884 ffi_call_unix64 + 76\n[bt] (4) 4 ??? 0x0000700000e63d70 0x0 + 123145317399920\n\n'

最佳答案

错误已修复。只需要改变

d_input = xgb.DMatrix([].append(input_vector))

d_input = xgb.DMatrix([[].append(input_vector)])

异常信息很奇怪。我对此感到困惑。

关于python - 如何修复 'DMatrix/Booster has not been intialized or has already been disposed ' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56249115/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com