Commit
·
c972581
1
Parent(s):
484451a
Update app.py
Browse files
app.py
CHANGED
|
@@ -83,18 +83,45 @@ def quant_evaluation(n_runs):
|
|
| 83 |
plt.ylabel("inertia")
|
| 84 |
plt.legend(plots, legends)
|
| 85 |
plt.title("Mean inertia for various k-means init across %d runs" % n_runs)
|
| 86 |
-
return plt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
with gr.Blocks(theme=theme) as demo:
|
| 89 |
gr.Markdown('''
|
| 90 |
-
<div>
|
| 91 |
<h1 style='text-align: center'>Empirical evaluation of the impact of k-means initialization 📊</h1>
|
| 92 |
-
</div>
|
| 93 |
''')
|
| 94 |
gr.Markdown(description)
|
| 95 |
n_runs = gr.Slider(minimum=1, maximum=10, step=1, value=5, label="Number of Evaluation Runs")
|
| 96 |
run_button = gr.Button('Evaluate')
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
| 98 |
run_button.click(fn=quant_evaluation, inputs=[n_runs], outputs=plot_inertia)
|
|
|
|
| 99 |
|
| 100 |
demo.launch()
|
|
|
|
| 83 |
plt.ylabel("inertia")
|
| 84 |
plt.legend(plots, legends)
|
| 85 |
plt.title("Mean inertia for various k-means init across %d runs" % n_runs)
|
| 86 |
+
return plt
|
| 87 |
+
|
| 88 |
+
def qual_evaluation():
|
| 89 |
+
X, y = make_data(random_state, n_samples_per_center, grid_size, scale)
|
| 90 |
+
km = MiniBatchKMeans(
|
| 91 |
+
n_clusters=n_clusters, init="random", n_init=1, random_state=random_state
|
| 92 |
+
).fit(X)
|
| 93 |
+
|
| 94 |
+
plt.figure()
|
| 95 |
+
for k in range(n_clusters):
|
| 96 |
+
my_members = km.labels_ == k
|
| 97 |
+
color = cm.nipy_spectral(float(k) / n_clusters, 1)
|
| 98 |
+
plt.plot(X[my_members, 0], X[my_members, 1], ".", c=color)
|
| 99 |
+
cluster_center = km.cluster_centers_[k]
|
| 100 |
+
plt.plot(
|
| 101 |
+
cluster_center[0],
|
| 102 |
+
cluster_center[1],
|
| 103 |
+
"o",
|
| 104 |
+
markerfacecolor=color,
|
| 105 |
+
markeredgecolor="k",
|
| 106 |
+
markersize=6,
|
| 107 |
+
)
|
| 108 |
+
plt.title(
|
| 109 |
+
"Example cluster allocation with a single random init\nwith MiniBatchKMeans"
|
| 110 |
+
)
|
| 111 |
+
return plt
|
| 112 |
|
| 113 |
with gr.Blocks(theme=theme) as demo:
|
| 114 |
gr.Markdown('''
|
|
|
|
| 115 |
<h1 style='text-align: center'>Empirical evaluation of the impact of k-means initialization 📊</h1>
|
|
|
|
| 116 |
''')
|
| 117 |
gr.Markdown(description)
|
| 118 |
n_runs = gr.Slider(minimum=1, maximum=10, step=1, value=5, label="Number of Evaluation Runs")
|
| 119 |
run_button = gr.Button('Evaluate')
|
| 120 |
+
run_button_qual = gr.Button('Generate Cluster Allocations')
|
| 121 |
+
with gr.Row():
|
| 122 |
+
plot_inertia = gr.Plot()
|
| 123 |
+
plot_vis = gr.Plot()
|
| 124 |
run_button.click(fn=quant_evaluation, inputs=[n_runs], outputs=plot_inertia)
|
| 125 |
+
run_button_qual.click(fn=qual_evaluation, inputs=[], outputs=plot_vis)
|
| 126 |
|
| 127 |
demo.launch()
|