XPMaster commited on
Commit
f25d93a
·
1 Parent(s): 296a6db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -21
app.py CHANGED
@@ -83,29 +83,55 @@ with tab1:
83
  df = pd.DataFrame(X, columns=iris.feature_names)
84
  df['cluster'] = y_kmeans
85
 
86
- fig = px.scatter(df, x=df.columns[0], y=df.columns[1], color='cluster',
87
- title='Visualizing Groups with K-Means Clustering',
88
- labels={df.columns[0]: 'Feature 1', df.columns[1]: 'Feature 2'},
89
- color_continuous_scale=px.colors.qualitative.Set1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
- # Remove the legend
92
- #fig.update_layout(showlegend=False)
93
- fig.update_layout(width=1200, height=500)
94
  # Add user input as a star marker
95
- fig.add_scatter(x=[user_features[0]], y=[user_features[1]], mode='markers', marker=dict(symbol='star', size=30, color='white'))
96
- fig.update_coloraxes(showscale=False)
97
- #fig.update_traces(visible='legendonly')
98
- # Add annotation for user input
99
- fig.add_annotation(
100
- x=user_features[0],
101
- y=user_features[1],
102
- xshift=10,
103
- text="Your Flower ("+dmojis[(predicted_cluster[0]+1)]+")",
104
- font=dict(color='white', size=30),
105
- arrowhead=2,
106
- ax=10,
107
- ay=-40
108
- )
109
 
110
  # Add centroids with group numbers
111
  for i, coord in enumerate(kmeans.cluster_centers_):
@@ -116,6 +142,10 @@ with tab1:
116
  showarrow=True,
117
  font=dict(color='white', size=30)
118
  )
 
 
 
 
119
 
120
 
121
  st.write("""
 
83
  df = pd.DataFrame(X, columns=iris.feature_names)
84
  df['cluster'] = y_kmeans
85
 
86
+ # fig = px.scatter(df, x=df.columns[0], y=df.columns[1], color='cluster',
87
+ # title='Visualizing Groups with K-Means Clustering',
88
+ # labels={df.columns[0]: 'Feature 1', df.columns[1]: 'Feature 2'},
89
+ # color_continuous_scale=px.colors.qualitative.Set1)
90
+
91
+ # # Remove the legend
92
+ # #fig.update_layout(showlegend=False)
93
+ # fig.update_layout(width=1200, height=500)
94
+ # # Add user input as a star marker
95
+ # fig.add_scatter(x=[user_features[0]], y=[user_features[1]], mode='markers', marker=dict(symbol='star', size=30, color='white'))
96
+ # fig.update_coloraxes(showscale=False)
97
+ # #fig.update_traces(visible='legendonly')
98
+ # # Add annotation for user input
99
+ # fig.add_annotation(
100
+ # x=user_features[0],
101
+ # y=user_features[1],
102
+ # xshift=10,
103
+ # text="Your Flower ("+dmojis[(predicted_cluster[0]+1)]+")",
104
+ # font=dict(color='white', size=30),
105
+ # arrowhead=2,
106
+ # ax=10,
107
+ # ay=-40
108
+ # )
109
+
110
+ # # Add centroids with group numbers
111
+ # for i, coord in enumerate(kmeans.cluster_centers_):
112
+ # fig.add_annotation(
113
+ # x=coord[0],
114
+ # y=coord[1],
115
+ # text=dmojis[i+1],
116
+ # showarrow=True,
117
+ # font=dict(color='white', size=30)
118
+ # )
119
+
120
+ # For tab1
121
+ fig = go.Figure()
122
+
123
+ # Add shaded regions
124
+ for cluster in np.unique(y_kmeans):
125
+ cluster_data = df[df['cluster'] == cluster]
126
+ x_data = cluster_data[df.columns[0]]
127
+ y_data = cluster_data[df.columns[1]]
128
+ fig.add_trace(go.Histogram2dContour(x=x_data, y=y_data, colorscale=px.colors.qualitative.Set1, showscale=False, opacity=0.8))
129
+
130
+ # Add scatter plot
131
+ fig.add_trace(go.Scatter(x=df[df.columns[0]], y=df[df.columns[1]], mode='markers', marker=dict(color=y_kmeans, colorscale=px.colors.qualitative.Set1), showlegend=False))
132
 
 
 
 
133
  # Add user input as a star marker
134
+ fig.add_trace(go.Scatter(x=[user_features[0]], y=[user_features[1]], mode='markers', marker=dict(symbol='star', size=30, color='white')))
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
  # Add centroids with group numbers
137
  for i, coord in enumerate(kmeans.cluster_centers_):
 
142
  showarrow=True,
143
  font=dict(color='white', size=30)
144
  )
145
+
146
+ # Update layout
147
+ fig.update_layout(width=1200, height=500)
148
+
149
 
150
 
151
  st.write("""