Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -79,7 +79,6 @@ with tab1:
|
|
| 79 |
##### Clustering with K-Means is a machine learning concept like tidying a messy room by grouping similar items, but for data instead of physical objects.
|
| 80 |
""")
|
| 81 |
|
| 82 |
-
|
| 83 |
# Check if 'use_pca' is already in the session state
|
| 84 |
if 'use_pca' not in st.session_state:
|
| 85 |
st.session_state.use_pca = True
|
|
@@ -92,7 +91,6 @@ with tab1:
|
|
| 92 |
else:
|
| 93 |
X_transformed = X[:, :2] # Just use the first two features for visualization
|
| 94 |
user_features_transformed = user_features[:2]
|
| 95 |
-
|
| 96 |
|
| 97 |
st.write("""
|
| 98 |
### Visualizing Groups
|
|
@@ -123,7 +121,7 @@ with tab1:
|
|
| 123 |
fig.add_trace(go.Scatter(x=x_data[hull.vertices], y=y_data[hull.vertices], fill='toself', fillcolor=px.colors.qualitative.Set1[cluster], opacity=0.5, line=dict(width=0), showlegend=False))
|
| 124 |
|
| 125 |
# Add scatter plot based on PCA toggle
|
| 126 |
-
if use_pca:
|
| 127 |
fig.add_trace(go.Scatter(x=df_transformed['Feature1'], y=df_transformed['Feature2'], mode='markers', marker=dict(color=y_kmeans, colorscale=px.colors.qualitative.Set1), showlegend=False))
|
| 128 |
else:
|
| 129 |
fig.add_trace(go.Scatter(x=df_transformed['Feature1'], y=df_transformed['Feature2'], mode='markers', marker=dict(color=y_kmeans, colorscale=px.colors.qualitative.Set1, symbol='square'), showlegend=False))
|
|
@@ -144,13 +142,17 @@ with tab1:
|
|
| 144 |
# Update layout
|
| 145 |
fig.update_layout(width=1200, height=500)
|
| 146 |
st.plotly_chart(fig)
|
| 147 |
-
|
| 148 |
# Checkbox after the plot
|
| 149 |
if st.checkbox('Use PCA for Visualization', value=st.session_state.use_pca):
|
| 150 |
st.session_state.use_pca = True
|
| 151 |
else:
|
| 152 |
st.session_state.use_pca = False
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
st.write(f"##### Overlapping clusters mean some flowers are very similar and hard to tell apart just by looking at these features.")
|
| 156 |
st.write(f"# Based on your flower data (⭐), it likely belongs to **Group {dmojis[predicted_cluster[0]+1]}**")
|
|
@@ -162,6 +164,7 @@ with tab1:
|
|
| 162 |
""")
|
| 163 |
|
| 164 |
|
|
|
|
| 165 |
with tab2:
|
| 166 |
st.write("""
|
| 167 |
## Advanced Overview of Clustering
|
|
|
|
| 79 |
##### Clustering with K-Means is a machine learning concept like tidying a messy room by grouping similar items, but for data instead of physical objects.
|
| 80 |
""")
|
| 81 |
|
|
|
|
| 82 |
# Check if 'use_pca' is already in the session state
|
| 83 |
if 'use_pca' not in st.session_state:
|
| 84 |
st.session_state.use_pca = True
|
|
|
|
| 91 |
else:
|
| 92 |
X_transformed = X[:, :2] # Just use the first two features for visualization
|
| 93 |
user_features_transformed = user_features[:2]
|
|
|
|
| 94 |
|
| 95 |
st.write("""
|
| 96 |
### Visualizing Groups
|
|
|
|
| 121 |
fig.add_trace(go.Scatter(x=x_data[hull.vertices], y=y_data[hull.vertices], fill='toself', fillcolor=px.colors.qualitative.Set1[cluster], opacity=0.5, line=dict(width=0), showlegend=False))
|
| 122 |
|
| 123 |
# Add scatter plot based on PCA toggle
|
| 124 |
+
if st.session_state.use_pca:
|
| 125 |
fig.add_trace(go.Scatter(x=df_transformed['Feature1'], y=df_transformed['Feature2'], mode='markers', marker=dict(color=y_kmeans, colorscale=px.colors.qualitative.Set1), showlegend=False))
|
| 126 |
else:
|
| 127 |
fig.add_trace(go.Scatter(x=df_transformed['Feature1'], y=df_transformed['Feature2'], mode='markers', marker=dict(color=y_kmeans, colorscale=px.colors.qualitative.Set1, symbol='square'), showlegend=False))
|
|
|
|
| 142 |
# Update layout
|
| 143 |
fig.update_layout(width=1200, height=500)
|
| 144 |
st.plotly_chart(fig)
|
| 145 |
+
|
| 146 |
# Checkbox after the plot
|
| 147 |
if st.checkbox('Use PCA for Visualization', value=st.session_state.use_pca):
|
| 148 |
st.session_state.use_pca = True
|
| 149 |
else:
|
| 150 |
st.session_state.use_pca = False
|
| 151 |
+
|
| 152 |
+
if st.session_state.use_pca:
|
| 153 |
+
st.write("""
|
| 154 |
+
##### 🧠 PCA (Principal Component Analysis) is like looking at a messy room from the best angle to see the most mess. It helps us see our data more clearly!
|
| 155 |
+
""")
|
| 156 |
|
| 157 |
st.write(f"##### Overlapping clusters mean some flowers are very similar and hard to tell apart just by looking at these features.")
|
| 158 |
st.write(f"# Based on your flower data (⭐), it likely belongs to **Group {dmojis[predicted_cluster[0]+1]}**")
|
|
|
|
| 164 |
""")
|
| 165 |
|
| 166 |
|
| 167 |
+
|
| 168 |
with tab2:
|
| 169 |
st.write("""
|
| 170 |
## Advanced Overview of Clustering
|