Reputation: 75
Is it possible to train an XGboost model in python and use the saved model to predict in spark environment? That is, I want to be able to train the XGboost model using sklearn, save the model, Load the saved model in spark and predict in spark. Is this possible?
I see the below issues when I train and predict different bindings of XGBoost:
During training I would be using XGBoost in python, and when predicting I would be using XGBoost in mllib.
I have to load the saved model from XGBoost python (Eg: XGBoost.model file) to be predicted in spark, would this model be compatible to be used with the predict function in the mllib.
The data input formats of both XGBoost in python and XGBoost in spark mllib are different. Spark takes vector assembled format but with python, we can feed the dataframe as such. So, how do I feed the data when I am trying to predict in spark with a model trained in python. Can I feed the data without vector assembler? Would XGboost predict function in spark mllib take non-vector assembled data as input?
Upvotes: 2
Views: 1671
Reputation: 2767
Here is a similar implementation of what you are looking for. I have a SO post explaining details as I am trying to troubleshoot the errors described in the post to get the code in the notebook working.
XGBoost Spark One Model Per Worker Integration
The idea is to train using xgboost
and then via spark
orchestrate each model to run on a spark worker
and then predictions can be applied via xgboost
predict_proba()
or spark ml
predict()
.
Upvotes: 0
Reputation: 725
you can
This all can be in one script, you spark-submit, but to make the things more concise, i will recommend split train/test in two script.
Because step2,3 are happening at driver level, not using any cluster resource, your worker are not doing anything
Upvotes: 0
Reputation: 3696
You can run your python script on spark using spark-submit
command so that can compile your python code on spark and then you can predict the value in spark.
Upvotes: 0