Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Machine Learning Model Serving Patterns and Best Practices

You're reading from   Machine Learning Model Serving Patterns and Best Practices A definitive guide to deploying, monitoring, and providing accessibility to ML models in production

Arrow left icon
Product type Paperback
Published in Dec 2022
Publisher Packt
ISBN-13 9781803249902
Length 336 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Md Johirul Islam Md Johirul Islam
Author Profile Icon Md Johirul Islam
Md Johirul Islam
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Part 1:Introduction to Model Serving
2. Chapter 1: Introducing Model Serving FREE CHAPTER 3. Chapter 2: Introducing Model Serving Patterns 4. Part 2:Patterns and Best Practices of Model Serving
5. Chapter 3: Stateless Model Serving 6. Chapter 4: Continuous Model Evaluation 7. Chapter 5: Keyed Prediction 8. Chapter 6: Batch Model Serving 9. Chapter 7: Online Learning Model Serving 10. Chapter 8: Two-Phase Model Serving 11. Chapter 9: Pipeline Pattern Model Serving 12. Chapter 10: Ensemble Model Serving Pattern 13. Chapter 11: Business Logic Pattern 14. Part 3:Introduction to Tools for Model Serving
15. Chapter 12: Exploring TensorFlow Serving 16. Chapter 13: Using Ray Serve 17. Chapter 14: Using BentoML 18. Part 4:Exploring Cloud Solutions
19. Chapter 15: Serving ML Models using a Fully Managed AWS Sagemaker Cloud Solution 20. Index 21. Other Books You May Enjoy

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:

  1. 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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image