Best practices for deploying automated models
The deployment of automated models is more or less identical to the deployment of your normal machine learning models. It boils down to training the model first and then saving the model in some format. In the case of normal machine learning models, you could easily save the model to a .model
or .h5
file. There's no reason not to do the same with TPOT models.
If you remember from previous chapters, TPOT can export the best pipeline to a Python file so this pipeline can be used to train the model if it isn't trained already, and the model can be saved afterward. If the model is already trained, only the prediction is obtained.
The check for whether a model has been trained or not can be made by checking whether a file exists or not. If a model file exists, we can assume the model was trained, so we can load it and make a prediction. Otherwise, the model should be trained and saved first, and only then can the prediction be...