0
votes

I am looking to load in a model and am having trouble because the model that is was made with an older version of XGBoost. I have gone on their website and looked, but it does not give clear direction on what syntax will properly fix this and load the model properly. I also did not realize that XGBoost was even required when loading with joblib

Below is the code:

    def init():
        global model

        model_path =  'C:\\Users\\ow\\Documents\\Test_Classification_Model\\3rd\\model_AutoMLe8aaac5a731.pkl'
        model = joblib.load(model_path)
init()

And this is the error:

raise XGBoostError(py_str(_LIB.XGBGetLastError())) xgboost.core.XGBoostError: [15:33:27] C:\Users\Administrator\workspace\xgboost-win64_release_1.0.0\src\learner.cc:682: 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.

3

3 Answers

1
votes

Do as they suggest.

Create a new environment with Anaconda or whatever you are using. Load the model and serialize it as a JSON file. This way you make sure that it's not a binary file (so you can look at it with a normal text editor) and the XGBoost routines can take whatever fields they need. You probably simply pickled the model which means you saved the Python object to a binary file. This generally leads to problems when you switch machines or versions so in the end this is not recommended.

So once you have installed the right XGBoost version, you can use this script: https://github.com/dmlc/xgboost/blob/master/doc/python/convert_090to100.py

1
votes

You need to have xboost==0.90 in order to be able to use joblib to load pickled model. Load the model and serialize it to JSON.

1
votes

The version of xgboost in which you dumped the model and the version in which you are loading the model should be the same. For me, it worked by dumping the model again using the latest version of xgboost.

As initially I dumped the model in xgboost=0.90 but loading with xgboost=1.4.1.
So I dumped as well as load the model using xgboost=1.4.1 and it worked.

Hope it was helpful...