Using Flask to creat a Web API for a trained machine learning model to persist the model learning state and use it for predictions on the go. Since the focus of this project is to demonstrate the model integration to a website, a basic support vector machines model for predicting iris type is used.
Major steps involved from model side are:
- Create a model
- Dump the trained model using Joblib or pickle, Joblib is efficient when the datasize is more and numpy arrays are involved.
- Create a Flask API to receive the request from Website
- Read the Json request in to a data frame. Please note that shape of the input needs to be same as the shape of the input features used while training model.
- Load the persisted model
- Predict using the loaded model and return the prediction in Json format.
- open the nginx config files
- In the sites-available folder add the following line to redirct the reqeusts
location /python-api-modelname { proxy_pass http://localhost:8889; }
- restart the nginx server and test the connection on postman