-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_app.py
125 lines (111 loc) · 5.58 KB
/
streamlit_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import json
import numpy as np
import pandas as pd
import streamlit as st
from PIL import Image
from run_deployment import run_main
from zenml.integrations.mlflow.model_deployers import MLFlowModelDeployer
def main():
st.title("End to End Customer Satisfaction Pipeline with ZenML")
high_level_image = Image.open("_assets/high_level_overview.png")
st.image(high_level_image, caption="High Level Pipeline")
whole_pipeline_image = Image.open(
"_assets/training_and_deployment_pipeline_updated.png"
)
st.markdown(
"""
#### Problem Statement
The objective here is to predict the customer satisfaction score for a given order based on features like order status, price, payment, etc. I will be using [ZenML](https://zenml.io/) to build a production-ready pipeline to predict the customer satisfaction score for the next order or purchase. """
)
st.image(whole_pipeline_image, caption="Whole Pipeline")
st.markdown(
"""
Above is a figure of the whole pipeline, we first ingest the data, clean it, train the model, and evaluate the model, and if data source changes or any hyperparameter values changes, deployment will be triggered, and (re) trains the model and if the model meets minimum accuracy requirement, the model will be deployed.
"""
)
st.markdown(
"""
#### Description of Features
This app is designed to predict the customer satisfaction score for a given customer. You can input the features of the product listed below and get the customer satisfaction score.
| Models | Description |
| ------------- | - |
| Payment Sequential | Customer may pay an order with more than one payment method. If he does so, a sequence will be created to accommodate all payments. |
| Payment Installments | Number of installments chosen by the customer. |
| Payment Value | Total amount paid by the customer. |
| Price | Price of the product. |
| Freight Value | Freight value of the product. |
| Product Name length | Length of the product name. |
| Product Description length | Length of the product description. |
| Product photos Quantity | Number of product published photos |
| Product weight measured in grams | Weight of the product measured in grams. |
| Product length (CMs) | Length of the product measured in centimeters. |
| Product height (CMs) | Height of the product measured in centimeters. |
| Product width (CMs) | Width of the product measured in centimeters. |
"""
)
payment_sequential = st.sidebar.slider("Payment Sequential")
payment_installments = st.sidebar.slider("Payment Installments")
payment_value = st.number_input("Payment Value")
price = st.number_input("Price")
freight_value = st.number_input("freight_value")
product_name_length = st.number_input("Product name length")
product_description_length = st.number_input("Product Description length")
product_photos_qty = st.number_input("Product photos Quantity ")
product_weight_g = st.number_input("Product weight measured in grams")
product_length_cm = st.number_input("Product length (CMs)")
product_height_cm = st.number_input("Product height (CMs)")
product_width_cm = st.number_input("Product width (CMs)")
if st.button("Predict"):
model_deployer = MLFlowModelDeployer.get_active_model_deployer()
service = model_deployer.find_model_server(
pipeline_name="continuous_deployment_pipeline",
pipeline_step_name="mlflow_model_deployer_step",
)[0]
if service is None:
st.write(
"No service could be found. The pipeline will be run first to create a service."
)
run_main()
df = pd.DataFrame(
{
"payment_sequential": [payment_sequential],
"payment_installments": [payment_installments],
"payment_value": [payment_value],
"price": [price],
"freight_value": [freight_value],
"product_name_lenght": [product_name_length],
"product_description_lenght": [product_description_length],
"product_photos_qty": [product_photos_qty],
"product_weight_g": [product_weight_g],
"product_length_cm": [product_length_cm],
"product_height_cm": [product_height_cm],
"product_width_cm": [product_width_cm],
}
)
json_list = json.loads(json.dumps(list(df.T.to_dict().values())))
data = np.array(json_list)
pred = service.predict(data)
st.success(
"Your Customer Satisfactory rate(range between 0 - 5) with given product details is :-{}".format(
pred
)
)
if st.button("Results"):
st.write(
"We have experimented with two ensemble and tree based models and compared the performance of each model. The results are as follows:"
)
df = pd.DataFrame(
{
"Models": ["LightGBM", "Xgboost"],
"MSE": [1.804, 1.781],
"RMSE": [1.343, 1.335],
}
)
st.dataframe(df)
st.write(
"Following figure shows how important each feature is in the model that contributes to the target variable or contributes in predicting customer satisfaction rate."
)
image = Image.open("_assets/feature_importance_gain.png")
st.image(image, caption="Feature Importance Gain")
if __name__ == "__main__":
main()