我正在使用XGboost库进行预测。当我想加载pickle文件时,我遇到以下错误:
File "/Users/admin/space/ML/model_building/predictor.py", line 74, in load_regressor
self._regressor = pickle.load(f)
File "/Users/admin/.conda/envs/env/lib/python3.8/site-packages/xgboost/core.py", line 1496, in __setstate__
_check_call(
File "/Users/admin/.conda/envs/env/lib/python3.8/site-packages/xgboost/core.py", line 203, in _check_call
raise XGBoostError(py_str(_LIB.XGBGetLastError()))
xgboost.core.XGBoostError: [16:23:50] /Users/runner/miniforge3/conda-bld/xgboost-split_1631904775127/work/src/common/json.cc:458: Expecting: """, got: "76 ", around character position: 1
{L\0\0\0\0\0\0\0
^~~~~~~~~
Stack trace:
[bt] (0) 1 libxgboost.dylib 0x000000014c7dce74 dmlc::LogMessageFatal::~LogMessageFatal() + 116
[bt] (1) 2 libxgboost.dylib 0x000000014c80e5ce xgboost::JsonReader::Error(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) const + 1070
[bt] (2) 3 libxgboost.dylib 0x000000014c80f09b xgboost::JsonReader::Expect(char, char) + 299
[bt] (3) 4 libxgboost.dylib 0x000000014c80f93b xgboost::JsonReader::ParseObject() + 491
[bt] (4) 5 libxgboost.dylib 0x000000014c80e068 xgboost::JsonReader::Parse() + 456
[bt] (5) 6 libxgboost.dylib 0x000000014c813fce xgboost::Json::Load(xgboost::StringView) + 62
[bt] (6) 7 libxgboost.dylib 0x000000014c893a2f xgboost::LearnerIO::Load(dmlc::Stream*) + 607
[bt] (7) 8 libxgboost.dylib 0x000000014c7e822f XGBoosterUnserializeFromBuffer + 159
[bt] (8) 9 libffi.8.dylib 0x000000010e368d92 ffi_call_unix64 + 82
pickle文件已经在其他机器上测试过了,运行得很好,但是在我的机器上,使用相同版本的XGboost(1.6.1),我得到了这个错误。我该如何修复它?
1条答案
按热度按时间ybzsozfc1#
您到底想在那里加载什么-
xgboost.Booster
对象,还是其他什么?根据错误消息,你已经传递了一个
xgboost.Booster
字节流给标准的Pythonpickle.load
函数,这是没有意义的。注意,
pickle.load
函数抱怨数据流以{L
开头,这表示XGBoost通用二进制JSON(UBJSON)数据格式。