gamaba commited on
Commit
669453d
·
verified ·
1 Parent(s): 575ed06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -3
app.py CHANGED
@@ -1,9 +1,28 @@
1
  import gradio as gr
2
  import matplotlib
3
  matplotlib.use('Agg') # Non-interactive backend for Gradio
4
- import matplotlib.pyplot as plt
 
5
  import numpy as np
6
- import joblib, json
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # Load saved artifacts
9
  kmeans_loaded = joblib.load('kmeans_model.pkl')
@@ -98,6 +117,8 @@ def predict_segment(age, annual_income, spending_score):
98
  user_scaled = scaler_loaded.transform(user_input)
99
  cluster_id = int(kmeans_loaded.predict(user_scaled)[0])
100
 
 
 
101
  info = insights_loaded[cluster_id]
102
  color = SEGMENT_COLORS[cluster_id]
103
  emoji = SEGMENT_EMOJIS[cluster_id]
@@ -196,7 +217,7 @@ with gr.Blocks(css=css, theme=gr.themes.Base(primary_hue='blue'), title='Custome
196
 
197
  gr.Markdown("""
198
  ---
199
- **Segments:** ⚠️ Cautious Savers · 🚀 High Potential · 🧑‍💼 Standard Customers · 💰 Budget Shoppers · 👑 Premium Loyalists
200
  **Model:** K-Means (K=5, k-means++ init) · Scaler: StandardScaler · Dataset: Mall Customers
201
  """)
202
 
 
1
  import gradio as gr
2
  import matplotlib
3
  matplotlib.use('Agg') # Non-interactive backend for Gradio
4
+
5
+ import pandas as pd
6
  import numpy as np
7
+ import matplotlib.pyplot as plt
8
+ import matplotlib.cm as cm
9
+ import seaborn as sns
10
+ import plotly.express as px
11
+ import plotly.graph_objects as go
12
+ from plotly.subplots import make_subplots
13
+ import warnings
14
+ warnings.filterwarnings('ignore')
15
+
16
+ from sklearn.preprocessing import StandardScaler
17
+ from sklearn.cluster import KMeans
18
+ from sklearn.decomposition import PCA
19
+ from sklearn.manifold import TSNE
20
+ from sklearn.metrics import silhouette_score, silhouette_samples
21
+ import joblib
22
+ import io, base64
23
+ import json
24
+
25
+ K_OPTIMAL = 5
26
 
27
  # Load saved artifacts
28
  kmeans_loaded = joblib.load('kmeans_model.pkl')
 
117
  user_scaled = scaler_loaded.transform(user_input)
118
  cluster_id = int(kmeans_loaded.predict(user_scaled)[0])
119
 
120
+ K_OPTIMAL = 5
121
+
122
  info = insights_loaded[cluster_id]
123
  color = SEGMENT_COLORS[cluster_id]
124
  emoji = SEGMENT_EMOJIS[cluster_id]
 
217
 
218
  gr.Markdown("""
219
  ---
220
+ **Segments:** ⚠️ Cautious Savers · 🚀 High Potential · 🧑‍💼 Standard Customers · 💰 Budget Shoppers · 👑 Premium Loyalists
221
  **Model:** K-Means (K=5, k-means++ init) · Scaler: StandardScaler · Dataset: Mall Customers
222
  """)
223