0% found this document useful (0 votes)
16 views

Lecture 6 - Model deployment

This document covers the process of model deployment in machine learning, detailing the workflow from model training to monitoring and maintenance. It discusses deployment strategies such as containerization, serverless computing, and API endpoints, along with best practices for version control, documentation, and security. Additionally, it introduces Streamlit as a tool for building interactive web applications for machine learning projects, providing guidance on creating and deploying a demo app.

Uploaded by

Nga Phạm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Lecture 6 - Model deployment

This document covers the process of model deployment in machine learning, detailing the workflow from model training to monitoring and maintenance. It discusses deployment strategies such as containerization, serverless computing, and API endpoints, along with best practices for version control, documentation, and security. Additionally, it introduces Streamlit as a tool for building interactive web applications for machine learning projects, providing guidance on creating and deploying a demo app.

Uploaded by

Nga Phạm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Artificial Intelligence

Lecture 6 - Model deployment

Lecturer: Vu Trong Sinh


1
Contents
Introduction

Deployment Workflow

Deployment Strategies

Best Practices

Building Interactive Web Applications with Streamlit


Introduction
What is Model Deployment?

The process of making a trained


machine learning model available
for use in a production
environment.
Introduction
Importance of Deployment:

● Transforms models from experiments to practical solutions.


● Allows real-time predictions on new data.
● Enables integration into applications and systems.
Deployment Workflow

Model Model Model Monitoring and


Model Training
Selection Serialization Integration Maintenance

Develop and train the Choose the Serialize the trained Select a deployment Monitor model
machine learning best-performing model model to save its state framework or platform performance and
model using historical based on evaluation for future use. suitable for the update as needed to
data. results. application maintain effectiveness
requirements. over time.

Integrate the model


into the target
application or system.
Model Serialization
Model serialization refers to the process of saving the trained model's state to disk
in a format that can be easily loaded and reused later.

Techniques:

Common serialization formats include pickle (for Python objects), joblib, and
HDF5 (for large numerical arrays).

Some libraries, like scikit-learn, offer built-in serialization methods.


Deployment Framework
A deployment framework or platform provides the infrastructure and tools
necessary to deploy machine learning models in production environments.
● Choose a deployment framework based on factors such as scalability, ease of
use, compatibility with existing systems, and cost.
● Popular deployment frameworks/platforms include AWS SageMaker,
Microsoft Azure ML, Google Cloud AI Platform, and Docker containers.
Model Integration
Model integration involves incorporating the deployed machine learning model into
the target application or system where it will be used to make predictions.
● Depending on the deployment framework and application architecture,
integration can be achieved through APIs, SDKs, or direct embedding of the
model code into the application codebase.
● APIs enable remote access to the model for making predictions over the
network.
● SDKs provide libraries and tools to simplify model integration into specific
programming languages or platforms.
● Embedding involves directly including the model code within the application,
suitable for offline deployments.
Monitoring and Maintenance
Monitoring involves continuously tracking the performance and behavior of the deployed model in
real-time production environments. Maintenance refers to updating and improving the model over time to
ensure its effectiveness and relevance.

Monitoring Metrics:

Key performance indicators (KPIs) such as prediction accuracy, latency, throughput, and error rates.

Monitoring tools and dashboards can help visualize and analyze these metrics to detect anomalies or
degradation in performance.

Maintenance Tasks:

● Periodically retraining the model with new data to adapt to changing patterns and trends.
● Updating the model to incorporate new features, improve algorithms, or address performance issues
identified during monitoring.
● Implementing version control to track changes and roll back to previous versions if necessary.
Deployment Strategies
Containerization

Use containerization technologies like Docker to package the model and its
dependencies for easy deployment across different environments.

Serverless Computing

Leverage serverless platforms such as AWS Lambda or Google Cloud


Functions to deploy and run models without managing servers.
Deployment Strategies
API Endpoints

Expose the model as a RESTful API endpoint, allowing other applications to send
requests and receive predictions.

Edge Computing

Deploy models directly on edge devices (e.g., IoT devices or mobile devices) to
make predictions locally without relying on a centralized server.
Best Practices
Version Control

Use version control systems (e.g., Git) to track changes to the model code and configurations.

Documentation

Document the deployment process, including dependencies, environment setup, and deployment instructions.

Security

Implement security measures to protect sensitive data and prevent unauthorized access to the deployed
model.

Testing

Conduct thorough testing of the deployed model to ensure reliability and accuracy in real-world scenarios (A/B
testing)
Building Interactive Web Applications with Streamlit
What is Streamlit?

Getting Started with Streamlit

Example Streamlit App: Iris Classifier

Running the App

Deploy the demo app to Streamlit cloud


What is Streamlit?
Streamlit is an open-source Python
library for building interactive web
applications for machine learning
and data science projects.

It allows you to create interactive


dashboards and visualizations
directly from Python scripts with
minimal code.
Getting Started with Streamlit
Installation instructions

https://docs.streamlit.io/get-started/installation

- Command line
- Anaconda

Run a hello world example


Example Streamlit App: Iris Classifier
Let's create a simple Streamlit app for classifying Iris flowers using a pre-trained
machine learning model.

We'll define a sidebar for user input (e.g., selecting input features), and display the
model predictions in the main area.

Download the code materials along with the lecture slide


Running the App
Open a terminal and navigate to the directory
containing the script.

Run the iris_classifier.py script to build a


model

Run the app.py to create a demo page

streamlit run app.py


Streamlit fundamentals
https://docs.streamlit.io/get-started/fundamentals
Streamlit tutorial
https://docs.streamlit.io/get-started/tutorials

Follow the tutorial to build a single-page application, multi-page application


API References
https://docs.streamlit.io/library/api-reference
Deploy the demo app to Streamlit cloud
https://docs.streamlit.io/streamlit-community-cloud/get-started
Homework
Create a Streamlit demo app for:

- A housing price prediction model


- A bank churn prediction model

Find some alternative solution for ML demo application rather than Streamlit

You might also like