Update app.py
Browse files
app.py
CHANGED
@@ -41,23 +41,28 @@ 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:", ["
|
45 |
k_value = st.slider("Select k value:", 1, 10)
|
46 |
|
47 |
dataset_mapping = {
|
48 |
-
"
|
49 |
-
"
|
50 |
-
"
|
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 |
-
|
|
|
|
|
58 |
|
59 |
-
|
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)
|
|
|
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 |
+
combined_data = pd.concat([dataset_mapping[dataset_name][0] for dataset_name in datasets])
|
54 |
+
|
55 |
+
centroids, labels = apply_kmeans(combined_data.values, k_value)
|
56 |
+
|
57 |
fig, ax = plt.subplots(figsize=(8, 8))
|
58 |
|
59 |
for dataset_name in datasets:
|
60 |
data, marker = dataset_mapping[dataset_name]
|
61 |
+
subset_labels = labels[:len(data)]
|
62 |
+
ax.scatter(data['x'], data['y'], c=subset_labels, cmap='viridis', marker=marker, label=dataset_name)
|
63 |
+
labels = labels[len(data):]
|
64 |
|
65 |
+
ax.scatter(centroids[:, 0], centroids[:, 1], s=200, c='red', marker='X')
|
|
|
66 |
|
67 |
ax.set_xlim(0, 100)
|
68 |
ax.set_ylim(0, 100)
|