Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import plotly.express as px
|
|
| 8 |
import base64
|
| 9 |
import plotly.figure_factory as ff
|
| 10 |
import plotly.graph_objects as go
|
|
|
|
| 11 |
|
| 12 |
st.set_page_config(layout="wide")
|
| 13 |
|
|
@@ -120,12 +121,14 @@ with tab1:
|
|
| 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 |
-
|
|
|
|
|
|
|
| 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))
|
|
@@ -146,8 +149,6 @@ with tab1:
|
|
| 146 |
# Update layout
|
| 147 |
fig.update_layout(width=1200, height=500)
|
| 148 |
|
| 149 |
-
|
| 150 |
-
|
| 151 |
st.write("""
|
| 152 |
### Visualizing Groups
|
| 153 |
##### Here are the groups from our tidying method. Each color has a number at its center, representing its group.
|
|
|
|
| 8 |
import base64
|
| 9 |
import plotly.figure_factory as ff
|
| 10 |
import plotly.graph_objects as go
|
| 11 |
+
from scipy.spatial import ConvexHull
|
| 12 |
|
| 13 |
st.set_page_config(layout="wide")
|
| 14 |
|
|
|
|
| 121 |
# For tab1
|
| 122 |
fig = go.Figure()
|
| 123 |
|
| 124 |
+
# Add shaded regions using convex hull
|
| 125 |
for cluster in np.unique(y_kmeans):
|
| 126 |
cluster_data = df[df['cluster'] == cluster]
|
| 127 |
+
x_data = cluster_data[df.columns[0]].values
|
| 128 |
+
y_data = cluster_data[df.columns[1]].values
|
| 129 |
+
if len(cluster_data) > 2: # ConvexHull requires at least 3 points
|
| 130 |
+
hull = ConvexHull(cluster_data[[df.columns[0], df.columns[1]]])
|
| 131 |
+
fig.add_trace(go.Polygon(x=x_data[hull.vertices], y=y_data[hull.vertices], fillcolor=px.colors.qualitative.Set1[cluster], opacity=0.5))
|
| 132 |
|
| 133 |
# Add scatter plot
|
| 134 |
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))
|
|
|
|
| 149 |
# Update layout
|
| 150 |
fig.update_layout(width=1200, height=500)
|
| 151 |
|
|
|
|
|
|
|
| 152 |
st.write("""
|
| 153 |
### Visualizing Groups
|
| 154 |
##### Here are the groups from our tidying method. Each color has a number at its center, representing its group.
|