Implementing online model serving
In this section, we will train a dummy SGDRegressor model, use Flask to create a server and API for the online prediction endpoint, use Postman to send a request to the server, and update the model with the input data and the prediction made by the last model.
For the end-to-end example we are going to run, you need to import the following modules:
from flask import Flask, request import numpy as np import json from sklearn.linear_model import SGDRegressor
Let’s begin:
- First of all, let’s create a model with some dummy data in the following code snippet:
X = [
    [1, 1, 1],
    [1, 1, 1],
    [1, 1, 1],
    [2, 2, 2],
    [2, 2, 2],
    [2, 2, 2]
     ]
y = [1, 1, 1, 2, 2, 2]
model = SGDRegressor()
model.fit(X, y)
print("Initial coefficients")
print(model.coef_)
print("Initial...