Viraj2307 commited on
Commit
6d243a6
Β·
1 Parent(s): 7f2bee8

Enhanced Visualisation Changes

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py CHANGED
@@ -3,6 +3,7 @@ import pandas as pd
3
  import numpy as np
4
  import datetime as dt
5
  from sklearn.cluster import KMeans
 
6
  import matplotlib.pyplot as plt
7
  import seaborn as sns
8
  import plotly.express as px
@@ -130,6 +131,30 @@ fig_cluster = px.scatter_3d(
130
  )
131
  st.plotly_chart(fig_cluster)
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  # Product Recommendation
134
  st.header("🎯 Product Recommendations")
135
 
@@ -173,6 +198,27 @@ if st.button("Recommend for Cluster"):
173
  except KeyError:
174
  st.warning("The selected product is not in the vocabulary for this cluster.")
175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  # Export Data
177
  st.header("πŸ“€ Export Processed Data")
178
  if st.button("Export RFM Data"):
 
3
  import numpy as np
4
  import datetime as dt
5
  from sklearn.cluster import KMeans
6
+ from sklearn.decomposition import PCA
7
  import matplotlib.pyplot as plt
8
  import seaborn as sns
9
  import plotly.express as px
 
131
  )
132
  st.plotly_chart(fig_cluster)
133
 
134
+ #Enhanced RFM Analysis
135
+ st.header("πŸ“Š Enhanced RFM Analysis")
136
+
137
+ # Interactive RFM Heatmap
138
+ heatmap_data = rfm[["Recency", "Frequency", "Monetary", "Cluster"]].groupby("Cluster").mean()
139
+ fig, ax = plt.subplots(figsize=(10, 6))
140
+ sns.heatmap(heatmap_data, annot=True, fmt=".1f", cmap="coolwarm", cbar=True, ax=ax)
141
+ ax.set_title("Average RFM Values per Cluster", fontsize=16)
142
+ st.pyplot(fig)
143
+
144
+ # Animated RFM Scatter
145
+ st.subheader("πŸ“ˆ Animated RFM Scatter Plot")
146
+ fig_rfm_animated = px.scatter_3d(
147
+ rfm,
148
+ x="Recency",
149
+ y="Frequency",
150
+ z="Monetary",
151
+ color="Cluster",
152
+ animation_frame="Cluster", # Add animation based on clusters
153
+ title="RFM Clusters Over Time",
154
+ size="Monetary",
155
+ )
156
+ st.plotly_chart(fig_rfm_animated)
157
+
158
  # Product Recommendation
159
  st.header("🎯 Product Recommendations")
160
 
 
198
  except KeyError:
199
  st.warning("The selected product is not in the vocabulary for this cluster.")
200
 
201
+ # PCA to visualize Word2Vec embeddings
202
+ st.subheader("πŸ“Š Word2Vec Embedding Visualization")
203
+ vectors = model.wv[model.wv.key_to_index.keys()] # Product vectors
204
+ pca = PCA(n_components=2)
205
+ pca_result = pca.fit_transform(vectors)
206
+
207
+ # Create DataFrame for visualization
208
+ embedding_df = pd.DataFrame(pca_result, columns=["PCA1", "PCA2"])
209
+ embedding_df["Product"] = model.wv.key_to_index.keys()
210
+
211
+ # Interactive Plot
212
+ fig_embed = px.scatter(
213
+ embedding_df,
214
+ x="PCA1",
215
+ y="PCA2",
216
+ hover_data=["Product"],
217
+ title="Word2Vec Product Embeddings",
218
+ template="plotly_dark",
219
+ )
220
+ st.plotly_chart(fig_embed)
221
+
222
  # Export Data
223
  st.header("πŸ“€ Export Processed Data")
224
  if st.button("Export RFM Data"):