我已经在python中使用xgboost软件包构建了Xgb模型。我使用pickle和joblib保存了模型,该模型在我的Windows 10系统中完美运行。但这在我尝试运行的AWS实例中给出了错误。该错误似乎与序列化有关。
>>> import joblib
>>> joblib.load(xgb_low_lr_fin.sav)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'xgb_low_lr_fin' is not defined
>>> joblib.load("xgb_low_lr_fin.sav")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/joblib/numpy_pickle.py", line 598, in load
obj = _unpickle(fobj, filename, mmap_mode)
File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/joblib/numpy_pickle.py", line 526, in _unpickle
obj = unpickler.load()
File "/home/ubuntu/anaconda3/lib/python3.7/pickle.py", line 1085, in load
dispatch[key[0]](self)
File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/joblib/numpy_pickle.py", line 339, in load_build
Unpickler.load_build(self)
File "/home/ubuntu/anaconda3/lib/python3.7/pickle.py", line 1549, in load_build
setstate(state)
File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/xgboost-1.0.0_SNAPSHOT-py3.7.egg/xgboost/core.py", line 1132, in __setstate__
_LIB.XGBoosterUnserializeFromBuffer(handle, ptr, length))
File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/xgboost-1.0.0_SNAPSHOT-py3.7.egg/xgboost/core.py", line 189, in _check_call
raise XGBoostError(py_str(_LIB.XGBGetLastError()))
xgboost.core.XGBoostError: [10:43:02] src/learner.cc:660: Check failed: header == serialisation_header_ (
上面的代码在Windows和Mac OS中都可以正常工作。
当尝试加载在另一台机器上腌制过的腌制文件时,我遇到了类似的问题,这与腌制序列化在Python 2和Python 3中甚至在腌制本身的不同版本中有所不同有关。
尝试检查您的pickle和python版本,并使其匹配:)