Phase 4
Phase 4
Phase 4 focuses on deploying the trained model to a cloud platform for real-time use and
developing an interactive interface for end-users. The goal is to make the market segmentation
model accessible and usable in a production environment by exposing it via APIs and creating an
intuitive user interface. This phase ensures that stakeholders can interact with the model, make
predictions, and visualize segmentation results in real time.
To deploy the trained model, we use cloud platforms like AWS, Google Cloud, or Azure. These
platforms provide robust infrastructure and services that make it easy to host machine learning
models, expose them via APIs, and ensure scalability for real-time use.
1. Model Export: First, the trained machine learning model (including the autoencoder and
K-Means clustering) needs to be saved and exported. This can be done using the pickle
module or TensorFlow's model.save() function to save the model weights and
architecture.
2. Source code :
Create API for the Model: We can use frameworks like Flask or FastAPI to expose the
trained model via a RESTful API. This API will accept input data, make predictions using
the model, and return the results.
Source code :
app = Flask(__name__)
if __name__ == '__main__':
app.run(debug=True)
Deploy the API on Cloud: Once the API is developed, it can be deployed to a cloud platform
like AWS Lambda, Google Cloud Functions, or Azure Functions. These services allow us to
deploy serverless functions that handle incoming requests without the need to manage
infrastructure.
AWS: Using AWS Lambda, the Flask app can be containerized and deployed as a
serverless function using AWS API Gateway to expose the API endpoints.
Google Cloud: Using Google Cloud Functions or Google App Engine, we can deploy
the Flask app and expose it as a serverless API.
Azure: Azure Functions can be used to deploy the model as an API, and Azure API
Management can manage the API lifecycle.
To allow end-users to interact with the deployed model, we can develop a simple web interface.
This interface will accept user inputs, send the data to the model API, and display the
segmentation results. Frameworks like Flask, Streamlit, or React can be used for this purpose.
1. Using Streamlit: Streamlit is a fast and easy-to-use framework for building interactive
web applications. It allows us to quickly develop a user-friendly interface to interact with
the deployed machine learning model.
import streamlit as st
import requests
import numpy as np
# Set the title of the app
st.title('Customer Segmentation Using Deep Clustering')
1. Using React: For a more complex and interactive interface, we can use React. React
allows building dynamic single-page applications (SPAs) where users can input data and
interact with the model.
o React components can be used to create forms where users input data.
o When the form is submitted, a request is made to the Flask API, and the response
is displayed in the user interface.
o React provides tools to manage application state and handle asynchronous
operations efficiently.
To deploy the model and interface on cloud platforms, the following considerations should be
taken into account:
Scalability: Cloud platforms like AWS and Google Cloud provide auto-scaling features
that ensure the model can handle high traffic and large volumes of data in real time.
Security: Ensure the API is secured using authentication (e.g., API keys or OAuth) to
prevent unauthorized access to the model.
Monitoring: Set up monitoring tools to track the API’s performance, such as AWS
CloudWatch, Google Stackdriver, or Azure Monitor, to detect and troubleshoot issues.
Cost Management: Cloud platforms charge based on usage, so it is important to monitor
the resource consumption and optimize API calls and serverless functions to reduce costs.
In this phase, we successfully deployed the Advanced Market Segmentation model to a cloud
platform, exposed it via an API for real-time use, and developed an interactive web interface
using Streamlit. The deployment ensures that the model is accessible for real-time predictions,
and the user interface allows easy interaction with the model for segmenting customers based on
their attributes. By leveraging cloud platforms and modern web technologies, the project is now
fully deployed and ready for use in production environments.