JUNGU commited on
Commit
b74390d
ยท
1 Parent(s): 93dd1fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -2,9 +2,15 @@ import streamlit as st
2
  import pandas as pd
3
  import numpy as np
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)]
@@ -25,14 +31,13 @@ def apply_kmeans(data, k):
25
  labels = kmeans.labels_
26
  return centroids, labels
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
34
 
35
- if st.button("Initialize Datasets"):
36
  traffic_data = np.random.uniform(0, 100, (num_samples * len(traffic_centers), 2))
37
  nature_data = np.random.uniform(0, 100, (num_samples * len(nature_centers), 2))
38
  population_data = np.random.uniform(0, 100, (num_samples * len(population_centers), 2))
@@ -41,16 +46,15 @@ def main():
41
  nature_df = pd.DataFrame(nature_data, columns=["x", "y"])
42
  population_df = pd.DataFrame(population_data, columns=["x", "y"])
43
 
44
- datasets = st.multiselect("Choose datasets:", ["Traffic Accessibility", "Natural Environment", "Population Density"])
45
- k_value = st.slider("Select k value:", 1, 10)
46
 
47
  dataset_mapping = {
48
- "Traffic Accessibility": (traffic_df, 'o'),
49
- "Natural Environment": (nature_df, 'x'),
50
- "Population Density": (population_df, '^')
51
  }
52
 
53
- # Check if any dataset is selected
54
  if datasets:
55
  combined_data = pd.concat([dataset_mapping[dataset_name][0] for dataset_name in datasets])
56
 
@@ -66,9 +70,9 @@ def main():
66
  ax.scatter(centroids[:, 0], centroids[:, 1], s=200, c='red', marker='X')
67
  ax.set_xlim(0, 100)
68
  ax.set_ylim(0, 100)
69
- ax.set_title(f"K-means clustering result (k={k_value})")
70
  ax.legend()
71
  st.pyplot(fig)
72
 
73
  if __name__ == "__main__":
74
- main()
 
2
  import pandas as pd
3
  import numpy as np
4
  import matplotlib.pyplot as plt
5
+ import matplotlib.font_manager as fm
6
  from sklearn.cluster import KMeans
7
 
8
+ # Set the font to NanumGothic for Korean support
9
+ font_path = '/NanumGothic-Regular.ttf'
10
+ font = fm.FontProperties(fname=font_path).get_name()
11
+ plt.rc('font', family=font)
12
+
13
+ # Data Generation
14
  np.random.seed(42)
15
  num_samples = 30
16
  traffic_centers = [(20, 20), (80, 80)]
 
31
  labels = kmeans.labels_
32
  return centroids, labels
33
 
 
34
  def main():
35
+ st.title("K-means ํด๋Ÿฌ์Šคํ„ฐ๋ง ์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ")
36
 
37
  # Global variables declaration
38
  global traffic_df, nature_df, population_df
39
 
40
+ if st.button("๋ฐ์ดํ„ฐ์…‹ ์ดˆ๊ธฐํ™”"):
41
  traffic_data = np.random.uniform(0, 100, (num_samples * len(traffic_centers), 2))
42
  nature_data = np.random.uniform(0, 100, (num_samples * len(nature_centers), 2))
43
  population_data = np.random.uniform(0, 100, (num_samples * len(population_centers), 2))
 
46
  nature_df = pd.DataFrame(nature_data, columns=["x", "y"])
47
  population_df = pd.DataFrame(population_data, columns=["x", "y"])
48
 
49
+ datasets = st.multiselect("๋ฐ์ดํ„ฐ์…‹ ์„ ํƒ:", ["๊ตํ†ต์ ‘๊ทผ์„ฑ", "์ž์—ฐํ™˜๊ฒฝ", "์ธ๊ตฌ๋ฐ€์ง‘๋„"])
50
+ k_value = st.slider("k ๊ฐ’ ์„ ํƒ:", 1, 10)
51
 
52
  dataset_mapping = {
53
+ "๊ตํ†ต์ ‘๊ทผ์„ฑ": (traffic_df, 'o'),
54
+ "์ž์—ฐํ™˜๊ฒฝ": (nature_df, 'x'),
55
+ "์ธ๊ตฌ๋ฐ€์ง‘๋„": (population_df, '^')
56
  }
57
 
 
58
  if datasets:
59
  combined_data = pd.concat([dataset_mapping[dataset_name][0] for dataset_name in datasets])
60
 
 
70
  ax.scatter(centroids[:, 0], centroids[:, 1], s=200, c='red', marker='X')
71
  ax.set_xlim(0, 100)
72
  ax.set_ylim(0, 100)
73
+ ax.set_title(f"K-means ํด๋Ÿฌ์Šคํ„ฐ๋ง ๊ฒฐ๊ณผ (k={k_value})")
74
  ax.legend()
75
  st.pyplot(fig)
76
 
77
  if __name__ == "__main__":
78
+ main()