Below is how I trained an XGBClassifier and saved it:
import pickle
from xgboost import XGBClassifier
# train
model = XGBClassifier()
model.fit(X, y)
# export
pickle.dump(model, open('model.pickle', 'wb'))
This is how I loaded the model and made predictions
loaded_model = pickle.load(open('model.pickle', 'rb'))
y_pred = loaded_model.predict(X)
The model predictions are OK if the model was loaded from within the same python process where the training was performed, but the predictions are not OK (random) if the model was loaded from a different python process than the one used for training.
Note, I've the same problem if model.save_model
and model.load_model
were used instead of pickle.
The simple checks I did shows the model was saved and loaded properly; the dumps of model._Booster
(acquired via model._Booster.dump_model(some_file)
) and loaded_model._Booster
are identical.
Python version: 3.7.5
xgboost version: tried both 0.80 and 0.90
Any suggestion is appreciated.