Skip to content

Commit 5dd5eed

Browse files
committed
deploy: cabc92a
1 parent e1c75bb commit 5dd5eed

File tree

18 files changed

+64
-52
lines changed

18 files changed

+64
-52
lines changed
Binary file not shown.

_downloads/40d009986931086fe7524a6c6c645a2b/plot_benchmark_custom.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
},
106106
"outputs": [],
107107
"source": [
108-
"results = benchmark_radius_clustering()\n\n# Plot the results\nfig, axs = plt.subplot_mosaic(\n [\n [\"time\", \"time\", \"time\", \"time\"],\n [\"iris\", \"wine\", \"breast_cancer\", \"vehicle\"],\n [\"glass\", \"ionosphere\", \"synthetic\", \"yeast\"],\n ],\n layout=\"constrained\",\n figsize=(12, 8),\n)\nfig.suptitle(\"Benchmark of Radius Clustering Solvers\", fontsize=16)\n\naxs['time'].set_yscale('log') # Use logarithmic scale for better visibility\nfor algo, algo_results in results.items():\n # Plot execution time\n axs['time'].plot(\n DATASETS.keys(),\n algo_results[\"time\"],\n marker='o',\n label=algo,\n )\n # Plot number of clusters\n\nfor i, (name, (dataset, _)) in enumerate(DATASETS.items()):\n axs[name].bar(\n results.keys(),\n [results[algo][\"clusters\"][i] for algo in results.keys()],\n label=name,\n )\n axs[name].axhline(\n y=len(set(dataset.target)), # Number of unique classes in the dataset\n label=\"True number of clusters\",\n color='r',\n linestyle='--',\n )\n axs[name].set_title(name)\n axs[name].set_xlabel(\"Algorithms\")\n\naxs[\"iris\"].set_ylabel(\"Number of clusters\")\naxs[\"glass\"].set_ylabel(\"Number of clusters\")\n\naxs['time'].set_title(\"Execution Time (log scale)\")\naxs['time'].set_xlabel(\"Datasets\")\naxs['time'].set_ylabel(\"Time (seconds)\")\naxs['time'].legend(title=\"Algorithms\")\nplt.tight_layout()\nplt.show()"
108+
"results = benchmark_radius_clustering()\n\n# Plot the results\nfig, axs = plt.subplot_mosaic(\n [\n [\"time\", \"time\", \"time\", \"time\"],\n [\"iris\", \"wine\", \"breast_cancer\", \"vehicle\"],\n [\"glass\", \"ionosphere\", \"synthetic\", \"yeast\"],\n ],\n layout=\"constrained\",\n figsize=(12, 8),\n)\nfig.suptitle(\"Benchmark of Radius Clustering Solvers\", fontsize=16)\n\naxs['time'].set_yscale('log') # Use logarithmic scale for better visibility\n\nalgorithms = list(results.keys())\ndataset_names = list(DATASETS.keys())\nn_algos = len(algorithms)\nx_indices = np.arange(len(dataset_names)) # the label locations\nbar_width = 0.8 / n_algos # the width of the bars, with some padding\n\nfor i, algo in enumerate(algorithms):\n times = results[algo][\"time\"]\n # Calculate position for each bar in the group to center them\n position = x_indices - (n_algos * bar_width / 2) + (i * bar_width) + bar_width / 2\n axs['time'].bar(position, times, bar_width, label=algo)\n\nfor i, (name, (dataset, _)) in enumerate(DATASETS.items()):\n axs[name].bar(\n results.keys(),\n [results[algo][\"clusters\"][i] for algo in results.keys()],\n label=name,\n )\n axs[name].axhline(\n y=len(set(dataset.target)), # Number of unique classes in the dataset\n label=\"True number of clusters\",\n color='r',\n linestyle='--',\n )\n axs[name].set_title(name)\n\naxs[\"iris\"].set_ylabel(\"Number of clusters\")\naxs[\"glass\"].set_ylabel(\"Number of clusters\")\n\naxs['time'].set_title(\"Execution Time (log scale)\")\naxs['time'].set_xlabel(\"Datasets\")\naxs['time'].set_ylabel(\"Time (seconds)\")\naxs['time'].set_xticks(x_indices)\naxs['time'].set_xticklabels(dataset_names)\naxs['time'].legend(title=\"Algorithms\")\nplt.tight_layout()\nplt.show()"
109109
]
110110
},
111111
{
Binary file not shown.
Binary file not shown.
Binary file not shown.

_downloads/93da2569053d80f75b5eacdcdc03c396/plot_benchmark_custom.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,18 @@ def benchmark_radius_clustering():
184184
fig.suptitle("Benchmark of Radius Clustering Solvers", fontsize=16)
185185

186186
axs['time'].set_yscale('log') # Use logarithmic scale for better visibility
187-
for algo, algo_results in results.items():
188-
# Plot execution time
189-
axs['time'].plot(
190-
DATASETS.keys(),
191-
algo_results["time"],
192-
marker='o',
193-
label=algo,
194-
)
195-
# Plot number of clusters
187+
188+
algorithms = list(results.keys())
189+
dataset_names = list(DATASETS.keys())
190+
n_algos = len(algorithms)
191+
x_indices = np.arange(len(dataset_names)) # the label locations
192+
bar_width = 0.8 / n_algos # the width of the bars, with some padding
193+
194+
for i, algo in enumerate(algorithms):
195+
times = results[algo]["time"]
196+
# Calculate position for each bar in the group to center them
197+
position = x_indices - (n_algos * bar_width / 2) + (i * bar_width) + bar_width / 2
198+
axs['time'].bar(position, times, bar_width, label=algo)
196199

197200
for i, (name, (dataset, _)) in enumerate(DATASETS.items()):
198201
axs[name].bar(
@@ -207,14 +210,15 @@ def benchmark_radius_clustering():
207210
linestyle='--',
208211
)
209212
axs[name].set_title(name)
210-
axs[name].set_xlabel("Algorithms")
211213

212214
axs["iris"].set_ylabel("Number of clusters")
213215
axs["glass"].set_ylabel("Number of clusters")
214216

215217
axs['time'].set_title("Execution Time (log scale)")
216218
axs['time'].set_xlabel("Datasets")
217219
axs['time'].set_ylabel("Time (seconds)")
220+
axs['time'].set_xticks(x_indices)
221+
axs['time'].set_xticklabels(dataset_names)
218222
axs['time'].legend(title="Algorithms")
219223
plt.tight_layout()
220224
plt.show()
-20 KB
Loading
-5.81 KB
Loading
-1.18 KB
Loading

_sources/auto_examples/plot_benchmark_custom.rst.txt

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ Run the benchmark and plot the results
251251
--------------------------------------
252252
We run the benchmark and plot the results for each dataset.
253253

254-
.. GENERATED FROM PYTHON SOURCE LINES 170-223
254+
.. GENERATED FROM PYTHON SOURCE LINES 170-227
255255
256256
.. code-block:: Python
257257
@@ -272,15 +272,18 @@ We run the benchmark and plot the results for each dataset.
272272
fig.suptitle("Benchmark of Radius Clustering Solvers", fontsize=16)
273273
274274
axs['time'].set_yscale('log') # Use logarithmic scale for better visibility
275-
for algo, algo_results in results.items():
276-
# Plot execution time
277-
axs['time'].plot(
278-
DATASETS.keys(),
279-
algo_results["time"],
280-
marker='o',
281-
label=algo,
282-
)
283-
# Plot number of clusters
275+
276+
algorithms = list(results.keys())
277+
dataset_names = list(DATASETS.keys())
278+
n_algos = len(algorithms)
279+
x_indices = np.arange(len(dataset_names)) # the label locations
280+
bar_width = 0.8 / n_algos # the width of the bars, with some padding
281+
282+
for i, algo in enumerate(algorithms):
283+
times = results[algo]["time"]
284+
# Calculate position for each bar in the group to center them
285+
position = x_indices - (n_algos * bar_width / 2) + (i * bar_width) + bar_width / 2
286+
axs['time'].bar(position, times, bar_width, label=algo)
284287
285288
for i, (name, (dataset, _)) in enumerate(DATASETS.items()):
286289
axs[name].bar(
@@ -295,14 +298,15 @@ We run the benchmark and plot the results for each dataset.
295298
linestyle='--',
296299
)
297300
axs[name].set_title(name)
298-
axs[name].set_xlabel("Algorithms")
299301
300302
axs["iris"].set_ylabel("Number of clusters")
301303
axs["glass"].set_ylabel("Number of clusters")
302304
303305
axs['time'].set_title("Execution Time (log scale)")
304306
axs['time'].set_xlabel("Datasets")
305307
axs['time'].set_ylabel("Time (seconds)")
308+
axs['time'].set_xticks(x_indices)
309+
axs['time'].set_xticklabels(dataset_names)
306310
axs['time'].legend(title="Algorithms")
307311
plt.tight_layout()
308312
plt.show()
@@ -321,13 +325,13 @@ We run the benchmark and plot the results for each dataset.
321325

322326
.. code-block:: none
323327
324-
/home/runner/work/radius_clustering/radius_clustering/examples/plot_benchmark_custom.py:219: UserWarning: The figure layout has changed to tight
328+
/home/runner/work/radius_clustering/radius_clustering/examples/plot_benchmark_custom.py:223: UserWarning: The figure layout has changed to tight
325329
plt.tight_layout()
326330
327331
328332
329333
330-
.. GENERATED FROM PYTHON SOURCE LINES 224-231
334+
.. GENERATED FROM PYTHON SOURCE LINES 228-235
331335
332336
Conclusion
333337
----------
@@ -340,7 +344,7 @@ The difference plot can be very useful to see where the two clustering algorithm
340344

341345
.. rst-class:: sphx-glr-timing
342346

343-
**Total running time of the script:** (13 minutes 0.891 seconds)
347+
**Total running time of the script:** (13 minutes 0.295 seconds)
344348

345349

346350
.. _sphx_glr_download_auto_examples_plot_benchmark_custom.py:

0 commit comments

Comments
 (0)