Home > Back-end >  XGBoost Error when saving and loading xgboost model using Pickle, JSON and JobLib
XGBoost Error when saving and loading xgboost model using Pickle, JSON and JobLib

Time:12-05

I have trained and saved an xgboost regressor model in Jupyter Notebook (Google Colab) and tried to load it in my local machine without success. I have tried to save and load the model in multiple formats: .pkl using pickle library, .sav using joblib library or .json.

When I load the model in VS Code, I get the following error:

raise XGBoostError(py_str(_LIB.XGBGetLastError())) xgboost.core.XGBoostError: [10:56:21] ../src/c_api/c_api.cc:846: Check failed: str[0] == '{' (

What is the problem here?

CodePudding user response:

The issue was a mismatch between the two versions of xgboost when saving the model in Google Colab (xgboost version 0.9) and loading the model in my local Python environment (xgboost version 1.5.1).

I managed to solve the problem by upgrading my xgboost package to the latest version (xgboost version 1.7.1) both on Google Colab and on my local Python environment. I resaved the model and re-loaded it using the newly saved file.

Now the loading works well without any errors.

I will leave my post here on Stackoverflow just in case it may be useful for someone else.

  • Related