Update app.py
Browse files
app.py
CHANGED
@@ -4,19 +4,20 @@ 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 |
|
11 |
traffic_data = np.random.uniform(0, 100, (num_samples * len(traffic_centers), 2))
|
12 |
nature_data = np.random.uniform(0, 100, (num_samples * len(nature_centers), 2))
|
13 |
population_data = np.random.uniform(0, 100, (num_samples * len(population_centers), 2))
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
traffic_df_uniform.head(), nature_df_uniform.head(), population_df_uniform.head()
|
20 |
|
21 |
def apply_kmeans(data, k):
|
22 |
kmeans = KMeans(n_clusters=k, random_state=42).fit(data)
|
@@ -24,23 +25,18 @@ def apply_kmeans(data, k):
|
|
24 |
labels = kmeans.labels_
|
25 |
return centroids, labels
|
26 |
|
27 |
-
def generate_data():
|
28 |
-
global traffic_df, nature_df, population_df
|
29 |
-
|
30 |
-
# ๋๋ค๋ฐ์ดํฐ ์์ฑ
|
31 |
-
traffic_data = np.random.uniform(0, 100, (num_samples, 2))
|
32 |
-
nature_data = np.random.uniform(0, 100, (num_samples, 2))
|
33 |
-
population_data = np.random.uniform(0, 100, (num_samples, 2))
|
34 |
-
|
35 |
-
traffic_df = pd.DataFrame(traffic_data, columns=["x", "y"])
|
36 |
-
nature_df = pd.DataFrame(nature_data, columns=["x", "y"])
|
37 |
-
population_df = pd.DataFrame(population_data, columns=["x", "y"])
|
38 |
-
|
39 |
def main():
|
40 |
st.title("K-means Clustering Simulator")
|
41 |
|
42 |
if st.button("Initialize Datasets"):
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
datasets = st.multiselect("Choose datasets:", ["๊ตํต์ ๊ทผ์ฑ", "์์ฐํ๊ฒฝ", "์ธ๊ตฌ๋ฐ์ง๋"])
|
45 |
k_value = st.slider("Select k value:", 1, 10)
|
46 |
|
@@ -50,7 +46,6 @@ def main():
|
|
50 |
"์ธ๊ตฌ๋ฐ์ง๋": population_df
|
51 |
}
|
52 |
|
53 |
-
# ์๋ฌด ๊ฐ๋ ์์๋
|
54 |
if datasets:
|
55 |
combined_data = pd.concat([dataset_mapping[dataset_name] for dataset_name in datasets])
|
56 |
|
@@ -67,4 +62,3 @@ def main():
|
|
67 |
|
68 |
if __name__ == "__main__":
|
69 |
main()
|
70 |
-
|
|
|
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)]
|
11 |
+
nature_centers = [(0, 80), (80, 0)]
|
12 |
+
population_centers = [(0, 0), (50, 50), (100, 100)]
|
13 |
|
14 |
traffic_data = np.random.uniform(0, 100, (num_samples * len(traffic_centers), 2))
|
15 |
nature_data = np.random.uniform(0, 100, (num_samples * len(nature_centers), 2))
|
16 |
population_data = np.random.uniform(0, 100, (num_samples * len(population_centers), 2))
|
17 |
|
18 |
+
traffic_df = pd.DataFrame(traffic_data, columns=["x", "y"])
|
19 |
+
nature_df = pd.DataFrame(nature_data, columns=["x", "y"])
|
20 |
+
population_df = pd.DataFrame(population_data, columns=["x", "y"])
|
|
|
|
|
21 |
|
22 |
def apply_kmeans(data, k):
|
23 |
kmeans = KMeans(n_clusters=k, random_state=42).fit(data)
|
|
|
25 |
labels = kmeans.labels_
|
26 |
return centroids, labels
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
def main():
|
29 |
st.title("K-means Clustering Simulator")
|
30 |
|
31 |
if st.button("Initialize Datasets"):
|
32 |
+
traffic_data = np.random.uniform(0, 100, (num_samples * len(traffic_centers), 2))
|
33 |
+
nature_data = np.random.uniform(0, 100, (num_samples * len(nature_centers), 2))
|
34 |
+
population_data = np.random.uniform(0, 100, (num_samples * len(population_centers), 2))
|
35 |
+
|
36 |
+
traffic_df = pd.DataFrame(traffic_data, columns=["x", "y"])
|
37 |
+
nature_df = pd.DataFrame(nature_data, columns=["x", "y"])
|
38 |
+
population_df = pd.DataFrame(population_data, columns=["x", "y"])
|
39 |
+
|
40 |
datasets = st.multiselect("Choose datasets:", ["๊ตํต์ ๊ทผ์ฑ", "์์ฐํ๊ฒฝ", "์ธ๊ตฌ๋ฐ์ง๋"])
|
41 |
k_value = st.slider("Select k value:", 1, 10)
|
42 |
|
|
|
46 |
"์ธ๊ตฌ๋ฐ์ง๋": population_df
|
47 |
}
|
48 |
|
|
|
49 |
if datasets:
|
50 |
combined_data = pd.concat([dataset_mapping[dataset_name] for dataset_name in datasets])
|
51 |
|
|
|
62 |
|
63 |
if __name__ == "__main__":
|
64 |
main()
|
|