Saving and Loading a Model
The last piece in mastering structured data is the ability to save and load the models that you have trained and fine-tuned. Training a new model every time we need a prediction will waste a lot of time, so being able to save a trained model is imperative for data scientists. The saved model allows us to replicate the results and to create apps and services that make use of the machine learning model. The steps are as follows:
- To save an XGBoost model, you need to call the save_model function.
model.save_model('wholesale-model.model')
- To load a previously saved model, you have to call load_model on an initialized XGBoost variable.
loaded_model = xgb.Booster({'nthread': 2})
loaded_model.load_model('wholesale-model.model')
Note
If you give XGBoost access to all the threads it can get, your computer might become slow while training or predicting.
You are now ready to get started on modeling your structured dataset using the XGBoost...