【问题标题】:How to fix 'DMatrix/Booster has not been intialized or has already been disposed ' error如何修复“DMatrix/Booster 尚未初始化或已被处理”错误
【发布时间】:2019-05-22 19:31:04
【问题描述】:

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

Python 3.7, xgboost 0.8, 康达

如果我从 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'

【问题讨论】:

    标签: python python-3.x xgboost


    【解决方案1】:

    错误已修复。只需要改变

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

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

    异常信息很奇怪。我被它弄糊涂了。

    【讨论】:

      猜你喜欢
      • 2021-06-23
      • 2018-03-07
      • 2011-10-31
      • 1970-01-01
      • 1970-01-01
      • 2020-05-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多