Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ def plot_clusters(data, k):
|
|
18 |
plt.title(f'K-means Clustering with k={k}')
|
19 |
plt.xlabel('Feature 1')
|
20 |
plt.ylabel('Feature 2')
|
21 |
-
plt_fig = plt
|
22 |
return plt_fig
|
23 |
|
24 |
def main():
|
@@ -27,28 +27,28 @@ def main():
|
|
27 |
|
28 |
# ๋ฐ์ดํฐ ์์ฑ ๋ฐ ์ถ๊ฐ
|
29 |
if 'data' not in st.session_state:
|
30 |
-
st.session_state.data = np.array([]).reshape(0, 2)
|
31 |
|
32 |
add_point = st.button("Add Random Data Point")
|
33 |
if add_point:
|
34 |
-
new_point
|
35 |
st.session_state.data = np.vstack([st.session_state.data, new_point])
|
36 |
|
37 |
-
x_coord = st.number_input("X Coordinate",
|
38 |
-
y_coord = st.number_input("Y Coordinate",
|
39 |
add_custom_point = st.button("Add Custom Data Point")
|
40 |
if add_custom_point:
|
41 |
st.session_state.data = np.vstack([st.session_state.data, [x_coord, y_coord]])
|
42 |
|
43 |
st.write("Here is the data:")
|
44 |
plt.scatter(st.session_state.data[:, 0], st.session_state.data[:, 1], s=50, cmap='viridis')
|
45 |
-
st.pyplot()
|
46 |
|
47 |
k = st.slider("Select the number of clusters (k)", 1, 10, 4)
|
48 |
st.write(f"You selected k={k}")
|
49 |
|
50 |
plt_fig = plot_clusters(st.session_state.data, k)
|
51 |
-
st.pyplot(plt_fig)
|
52 |
|
53 |
if __name__ == '__main__':
|
54 |
main()
|
|
|
18 |
plt.title(f'K-means Clustering with k={k}')
|
19 |
plt.xlabel('Feature 1')
|
20 |
plt.ylabel('Feature 2')
|
21 |
+
plt_fig = plt
|
22 |
return plt_fig
|
23 |
|
24 |
def main():
|
|
|
27 |
|
28 |
# ๋ฐ์ดํฐ ์์ฑ ๋ฐ ์ถ๊ฐ
|
29 |
if 'data' not in st.session_state:
|
30 |
+
st.session_state.data = np.array([]).reshape(0, 2)
|
31 |
|
32 |
add_point = st.button("Add Random Data Point")
|
33 |
if add_point:
|
34 |
+
new_point = np.array([[np.random.uniform(0, 100), np.random.uniform(0, 100)]])
|
35 |
st.session_state.data = np.vstack([st.session_state.data, new_point])
|
36 |
|
37 |
+
x_coord = st.number_input("X Coordinate", min_value=0.0, max_value=100.0, value=50.0)
|
38 |
+
y_coord = st.number_input("Y Coordinate", min_value=0.0, max_value=100.0, value=50.0)
|
39 |
add_custom_point = st.button("Add Custom Data Point")
|
40 |
if add_custom_point:
|
41 |
st.session_state.data = np.vstack([st.session_state.data, [x_coord, y_coord]])
|
42 |
|
43 |
st.write("Here is the data:")
|
44 |
plt.scatter(st.session_state.data[:, 0], st.session_state.data[:, 1], s=50, cmap='viridis')
|
45 |
+
st.pyplot()
|
46 |
|
47 |
k = st.slider("Select the number of clusters (k)", 1, 10, 4)
|
48 |
st.write(f"You selected k={k}")
|
49 |
|
50 |
plt_fig = plot_clusters(st.session_state.data, k)
|
51 |
+
st.pyplot(plt_fig)
|
52 |
|
53 |
if __name__ == '__main__':
|
54 |
main()
|