1
$\begingroup$

I am training an XGBoost-model on part of the ForestCover-Dataset. Then I save the trained model to json. Now I load the model and "update" the saved model with the data, that I previously omitted in training, using the "xgb_model" parameter of the train-method. I also save this "updated model" to json. What XGBoost does here is it simply adds trees to the old model.

What I want to do now is manipulate the updated model. My first idea was just to delete the "old part" of the model and see how only the new part does. So I manipulated the json-file and deleted the old trees, changed the tree_info parameter, changed the num_trees parameter and changed the IDs of all remaining trees to start at 0 again. Then I attempt to load this manipulated json-file as a new model. However, when trying to do so I get the following error:

XGBoostError                              Traceback (most recent call last)
Cell In[22], line 2
      1 bst_test = xgb.Booster()
----> 2 bst_test.load_model("modified.json")

File ~/personal/folder/lib/python3.10/site-packages/xgboost/core.py:2441, in Booster.load_model(self, fname)
   2437 if isinstance(fname, (str, os.PathLike)):
   2438     # assume file name, cannot use os.path.exist to check, file can be
   2439     # from URL.
   2440     fname = os.fspath(os.path.expanduser(fname))
-> 2441     _check_call(_LIB.XGBoosterLoadModel(
   2442         self.handle, c_str(fname)))
   2443 elif isinstance(fname, bytearray):
   2444     buf = fname

File ~/personal/folder/lib/python3.10/site-packages/xgboost/core.py:279, in _check_call(ret)
    268 """Check the return value of C API call
    269 
    270 This function will raise exception when error occurs.
   (...)
    276     return value from API calls
    277 """
    278 if ret != 0:
--> 279     raise XGBoostError(py_str(_LIB.XGBGetLastError()))

XGBoostError: [11:25:21] ../include/xgboost/json.h:81: Invalid cast, from Integer to String

Can anyone help me understand what is going on here?

$\endgroup$

1 Answer 1

1
$\begingroup$

In case anyone stumbles across a similar issue: The parameter "num_trees" is stored as a string not an integer. I updated it as integer, which caused the problem.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.