JUNGU commited on
Commit
6f4a9d3
ยท
1 Parent(s): 67ec54d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
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, _ = make_blobs(n_samples=1, centers=1, cluster_std=1.0)
35
  st.session_state.data = np.vstack([st.session_state.data, new_point])
36
 
37
- x_coord = st.number_input("X Coordinate", value=0.0)
38
- y_coord = st.number_input("Y Coordinate", value=0.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() # plt.show() ๋Œ€์‹  ์ด๋ฅผ ์‚ฌ์šฉ
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) # plt.show() ๋Œ€์‹  ์ด๋ฅผ ์‚ฌ์šฉ
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()