SauceCat / PDPbox

python partial dependence plot toolbox
http://pdpbox.readthedocs.io/en/latest/
MIT License
840 stars 129 forks source link

PDPbox saved XGBoost models do not play well with latest XGBoost #64

Closed sbushmanov closed 3 years ago

sbushmanov commented 4 years ago

I am trying to execute the code:

from pdpbox import pdp, get_dataset, info_plots
test_titanic = get_dataset.titanic()

And I'm having the below error. PDP 0.2.0+13.g73c6966 XGBoost 1.1.0-SNAPSHOT conda environment

Stacktrace:

XGBoostError                              Traceback (most recent call last)
<ipython-input-2-931a5e8d7b9f> in <module>
----> 1 test_titanic = get_dataset.titanic()

~/anaconda3/lib/python3.6/site-packages/PDPbox-0.2.0+13.g73c6966-py3.6.egg/pdpbox/get_dataset.py in titanic()
      7 
      8 def titanic():
----> 9         dataset = joblib.load(os.path.join(DIR, 'datasets/test_titanic.pkl'))
     10         return dataset
     11 

~/anaconda3/lib/python3.6/site-packages/joblib/numpy_pickle.py in load(filename, mmap_mode)
    603                     return load_compatibility(fobj)
    604 
--> 605                 obj = _unpickle(fobj, filename, mmap_mode)
    606 
    607     return obj

~/anaconda3/lib/python3.6/site-packages/joblib/numpy_pickle.py in _unpickle(fobj, filename, mmap_mode)
    527     obj = None
    528     try:
--> 529         obj = unpickler.load()
    530         if unpickler.compat_mode:
    531             warnings.warn("The file '%s' has been generated with a "

~/anaconda3/lib/python3.6/pickle.py in load(self)
   1048                     raise EOFError
   1049                 assert isinstance(key, bytes_types)
-> 1050                 dispatch[key[0]](self)
   1051         except _Stop as stopinst:
   1052             return stopinst.value

~/anaconda3/lib/python3.6/site-packages/joblib/numpy_pickle.py in load_build(self)
    340         NDArrayWrapper is used for backward compatibility with joblib <= 0.9.
    341         """
--> 342         Unpickler.load_build(self)
    343 
    344         # For backward compatibility, we support NDArrayWrapper objects.

~/anaconda3/lib/python3.6/pickle.py in load_build(self)
   1505         setstate = getattr(inst, "__setstate__", None)
   1506         if setstate is not None:
-> 1507             setstate(state)
   1508             return
   1509         slotstate = None

~/anaconda3/lib/python3.6/site-packages/xgboost/core.py in __setstate__(self, state)
   1096             ptr = (ctypes.c_char * len(buf)).from_buffer(buf)
   1097             _check_call(
-> 1098                 _LIB.XGBoosterUnserializeFromBuffer(handle, ptr, length))
   1099             state['handle'] = handle
   1100         self.__dict__.update(state)

~/anaconda3/lib/python3.6/site-packages/xgboost/core.py in _check_call(ret)
    187     """
    188     if ret != 0:
--> 189         raise XGBoostError(py_str(_LIB.XGBGetLastError()))
    190 
    191 

XGBoostError: [18:53:06] /home/sergey/xgboost/src/learner.cc:834: Check failed: header == serialisation_header_: 

  If you are loading a serialized model (like pickle in Python) generated by older
  XGBoost, please export the model by calling `Booster.save_model` from that version
  first, then load it back in current version.  There's a simple script for helping
  the process. See:

    https://xgboost.readthedocs.io/en/latest/tutorials/saving_model.html

  for reference to the script, and more details about differences between saving model and
  serializing.

Stack trace:
  [bt] (0) /home/sergey/anaconda3/lib/python3.6/site-packages/xgboost/lib/libxgboost.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x64) [0x7fe81e08c784]
  [bt] (1) /home/sergey/anaconda3/lib/python3.6/site-packages/xgboost/lib/libxgboost.so(xgboost::LearnerIO::Load(dmlc::Stream*)+0x674) [0x7fe81e19f444]
  [bt] (2) /home/sergey/anaconda3/lib/python3.6/site-packages/xgboost/lib/libxgboost.so(XGBoosterUnserializeFromBuffer+0x5e) [0x7fe81e07f61e]
  [bt] (3) /home/sergey/anaconda3/lib/python3.6/lib-dynload/../../libffi.so.6(ffi_call_unix64+0x4c) [0x7fe84c23d630]
  [bt] (4) /home/sergey/anaconda3/lib/python3.6/lib-dynload/../../libffi.so.6(ffi_call+0x22d) [0x7fe84c23cfed]
  [bt] (5) /home/sergey/anaconda3/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(_ctypes_callproc+0x2ce) [0x7fe84b3c509e]
  [bt] (6) /home/sergey/anaconda3/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(+0x13ad5) [0x7fe84b3c5ad5]
  [bt] (7) /home/sergey/anaconda3/bin/python -m ipykernel -f /home/sergey/.local/share/jupyter/runtime/kernel-813f0269-7bc5-4ef8-b890-fb9b799698ce.json(_PyObject_FastCallDict+0x8b) [0x559094256f8b]
  [bt] (8) /home/sergey/anaconda3/bin/python -m ipykernel -f /home/sergey/.local/share/jupyter/runtime/kernel-813f0269-7bc5-4ef8-b890-fb9b799698ce.json(+0x1a162e) [0x5590942e562e]
amir-rahnama commented 4 years ago

It has to do with the latest xgboost package. I bumped down the version of xgboost to 0.8 and it solved my issue:

pip install xgboost==0.80
SauceCat commented 3 years ago

It's fixed in the new version.