Path: blob/master/model_deployment/fastapi_kubernetes/tree_model_deployment.ipynb
1480 views
Table of Contents
Tree Model Deployment
We'll try and keep the data, feature engineering, model training part as short as possible as the main focus of the repo is to build a service on top of the model.
Model Training
Loads the dataset.
A quick train/test split.
Following the LightGBM Python Quickstart to train the model.
Quick evaluation of our regression model.
Saves the trained model under the app
folder.
Ensure the prediction between the model and the saved model matches. Here we pass in the whole test set.
We can also perform prediction for a single record. The caveat here is that .predict
expects a 2d array, hence for single record prediction, we need to reshape it to 2d first.
Calling the API
Before proceeding on to this section, we need to create the service first. Either follow the Docker Container section in the README to host the service locally through a container or power through the Azure Kubernetes Cluster section to host the service on Azure Kubernetes Cluster.
Once we host the service, and can test it using the request
library.
Change the url accordingly. And pass our features as a json body.
We've also implemented the endpoint for supporting batch calls, i.e. to get the scores for multiple records in a single call.