I have trained a model using sklearn api and saved the model
from xgboost.sklearn import XGBClassifier
model = XGBClassifier()
model.fit(X_train, y_train)
with open(path + '.pkl', 'wb') as file:
cPickle.dump(model, file)
Is there a way to load it with scala API?
If I train it using the python API (not the sklearn API) and save it using the:
model.save_model("trained_model.model")
then I can load it with scala using:
import ml.dmlc.xgboost4j.scala.XGBoost
val model = XGBoost.loadModel("trained_model.model")
Is there a similar way for loading a pkl formated model in scala?
Or alternatively is it possible to convert a sklearned-api-xgboost-model to a python-api-model? and after the python-api-model can be loaded using the above code.
Any insights?
For those who come up to this question, the solution is:
When you train a model using the sklearn API you can save as:
model._Booster.save_model("trained_model.model")
save_model is used in python API.
Later this model can be loaded in scala API as described in the question:
val model = XGBoost.loadModel("trained_model.model")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With