load xgboost model return NoneType

Viewed 1418

I have a problem in load xgboost model . when I save my xgboost model using model.save_model("xgbt.bin") and try to load it by this code : load_model=xgboost.Booster.load_model("xgbt.bin") then I print the type of load_model by this print(type(load_model)) and it's print <class 'NoneType'>

also when I try prediction=load_model.predict(api_data) I occured this error : AttributeError: 'NoneType' object has no attribute 'predict'

1 Answers

The XGBoost framework stores the model directly to the XGBoost Object. The function load_model itself returns the printed NoneType Object:

def load_model(self, fname: Union[str, bytearray, os.PathLike]) -> None

Loading the model, as shown below, will properly return the object you want:

import xgboost as xgb

xgb_model = xgb.Booster()
xgb_model.load_model(path_to_file)

Now you can predict as usual with:

predicted_values = xgb_model.predict(validation_data)
Related