Update app.py
Browse files
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
|
31 |
|
32 |
# Global variables declaration
|
33 |
global traffic_df, nature_df, population_df
|
34 |
|
35 |
-
if st.button("
|
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("
|
45 |
-
k_value = st.slider("
|
46 |
|
47 |
dataset_mapping = {
|
48 |
-
"
|
49 |
-
"
|
50 |
-
"
|
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
|
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()
|