3v324v23 commited on
Commit
e2967f3
·
1 Parent(s): 6d8ca31
Files changed (1) hide show
  1. app.py +11 -14
app.py CHANGED
@@ -96,24 +96,21 @@ with tab2:
96
 
97
  # Visualizations for Item Purchased distribution
98
  fig, ax = plt.subplots(figsize=(10, 5))
99
- sns.countplot(y=df['Item Purchased'], order=df['Item Purchased'].value_counts().index, palette='viridis', ax=ax)
100
  ax.set_title("Overall Item Purchase Distribution")
101
  ax.set_xlabel("Count")
102
  ax.set_ylabel("Item Purchased")
103
  st.pyplot(fig)
104
 
105
- # Heatmap for Matrix Visualization
106
- st.subheader("Feature Correlation Matrix")
107
- label_encoders = {}
108
- for col in categorical_features:
109
- le = LabelEncoder()
110
- df[col + '_Numeric'] = le.fit_transform(df[col])
111
- label_encoders[col] = le
112
-
113
- correlation_matrix = df[['Gender_Numeric', 'Purchase Amount (USD)', 'Previous Purchases', 'Frequency of Purchases_Numeric']].corr()
114
- fig, ax = plt.subplots(figsize=(10, 6))
115
- sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', fmt='.2f', ax=ax)
116
- st.pyplot(fig)
117
 
118
  with tab3:
119
  st.subheader("Enter Customer Details")
@@ -149,4 +146,4 @@ with tab3:
149
  # Display average purchase amount trend
150
  avg_purchase_amount = cluster_data.groupby('Item Purchased')['Purchase Amount (USD)'].mean()
151
  st.write("### Average Purchase Amount for Items in This Cluster:")
152
- st.write(avg_purchase_amount)
 
96
 
97
  # Visualizations for Item Purchased distribution
98
  fig, ax = plt.subplots(figsize=(10, 5))
99
+ sns.countplot(y=df['Item Purchased'], order=df['Item Purchased'].value_counts().index, hue=df['Item Purchased'], palette='viridis', ax=ax)
100
  ax.set_title("Overall Item Purchase Distribution")
101
  ax.set_xlabel("Count")
102
  ax.set_ylabel("Item Purchased")
103
  st.pyplot(fig)
104
 
105
+ # Separate Correlation Matrices for Each Label
106
+ labels = ['Gender', 'Frequency of Purchases', 'Item Purchased']
107
+ for label in labels:
108
+ df[f'{label}_Numeric'] = LabelEncoder().fit_transform(df[label])
109
+ correlation_matrix = df[[f'{label}_Numeric', 'Purchase Amount (USD)', 'Previous Purchases']].corr()
110
+ fig, ax = plt.subplots(figsize=(10, 6))
111
+ sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', fmt='.2f', ax=ax)
112
+ st.subheader(f"Feature Correlation Matrix for {label}")
113
+ st.pyplot(fig)
 
 
 
114
 
115
  with tab3:
116
  st.subheader("Enter Customer Details")
 
146
  # Display average purchase amount trend
147
  avg_purchase_amount = cluster_data.groupby('Item Purchased')['Purchase Amount (USD)'].mean()
148
  st.write("### Average Purchase Amount for Items in This Cluster:")
149
+ st.write(avg_purchase_amount)