JUNGU commited on
Commit
f33edaa
ยท
1 Parent(s): 10981ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -18
app.py CHANGED
@@ -4,7 +4,7 @@ import numpy as np
4
  import matplotlib.pyplot as plt
5
  from sklearn.cluster import KMeans
6
 
7
- # Data Generation
8
  np.random.seed(42)
9
  num_samples = 30
10
  traffic_centers = [(20, 20), (80, 80)]
@@ -27,7 +27,7 @@ def apply_kmeans(data, k):
27
 
28
 
29
  def main():
30
- st.title("K-means Clustering Simulator")
31
 
32
  # Global variables declaration
33
  global traffic_df, nature_df, population_df
@@ -45,24 +45,25 @@ def main():
45
  k_value = st.slider("Select k value:", 1, 10)
46
 
47
  dataset_mapping = {
48
- "๊ตํ†ต์ ‘๊ทผ์„ฑ": traffic_df,
49
- "์ž์—ฐํ™˜๊ฒฝ": nature_df,
50
- "์ธ๊ตฌ๋ฐ€์ง‘๋„": population_df
51
  }
52
-
53
- if datasets:
54
- combined_data = pd.concat([dataset_mapping[dataset_name] for dataset_name in datasets])
55
-
56
- fig, ax = plt.subplots(figsize=(8, 8))
 
57
 
58
- centroids, labels = apply_kmeans(combined_data.values, k_value)
59
- ax.scatter(combined_data['x'], combined_data['y'], c=labels, cmap='viridis')
60
  ax.scatter(centroids[:, 0], centroids[:, 1], s=200, c='red', marker='X')
61
-
62
- ax.set_xlim(0, 100)
63
- ax.set_ylim(0, 100)
64
- ax.set_title(f"K-means clustering result (k={k_value})")
65
- st.pyplot(fig)
 
66
 
67
  if __name__ == "__main__":
68
- main()
 
4
  import matplotlib.pyplot as plt
5
  from sklearn.cluster import KMeans
6
 
7
+ # ๋ฐ์ดํ„ฐ ์ƒ์„ฑ
8
  np.random.seed(42)
9
  num_samples = 30
10
  traffic_centers = [(20, 20), (80, 80)]
 
27
 
28
 
29
  def main():
30
+ st.title("K-means Clustering simulator \n k-means Clustering ์‹œ๋ฎฌ๋ ˆ์ด์…˜์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.")
31
 
32
  # Global variables declaration
33
  global traffic_df, nature_df, population_df
 
45
  k_value = st.slider("Select k value:", 1, 10)
46
 
47
  dataset_mapping = {
48
+ "๊ตํ†ต์ ‘๊ทผ์„ฑ": (traffic_df, 'o')
49
+ "์ž์—ฐํ™˜๊ฒฝ": (nature_df, 'x')
50
+ "์ธ๊ตฌ๋ฐ€์ง‘๋„": (population_df, 'โ–ฒ')
51
  }
52
+
53
+ fig, ax = plt.subplots(figsize=(8, 8))
54
+
55
+ for dataset_name in datasets:
56
+ data, marker = dataset_mapping[dataset_name]
57
+ centroids, labels = apply_kmeans(data.values, k_value)
58
 
59
+ ax.scatter(data['x'], data['y'], c=labels, cmap='viridis', marker=marker, label=dataset_name)
 
60
  ax.scatter(centroids[:, 0], centroids[:, 1], s=200, c='red', marker='X')
61
+
62
+ ax.set_xlim(0, 100)
63
+ ax.set_ylim(0, 100)
64
+ ax.set_title(f"K-means clustering result (k={k_value})")
65
+ ax.legend()
66
+ st.pyplot(fig)
67
 
68
  if __name__ == "__main__":
69
+ main()