From 00322d7ca04ae995c3f17fc205cce0c1285b10a4 Mon Sep 17 00:00:00 2001 From: SuccessMoses Date: Mon, 21 Oct 2024 13:36:57 -0700 Subject: [PATCH 01/12] DOC Linked examples for Affinity Propagation in thier docs --- sklearn/cluster/_affinity_propagation.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sklearn/cluster/_affinity_propagation.py b/sklearn/cluster/_affinity_propagation.py index 677421974bdc0..020fde1f3db8b 100644 --- a/sklearn/cluster/_affinity_propagation.py +++ b/sklearn/cluster/_affinity_propagation.py @@ -401,6 +401,9 @@ class AffinityPropagation(ClusterMixin, BaseEstimator): For an example usage, see :ref:`sphx_glr_auto_examples_cluster_plot_affinity_propagation.py`. + For a comparison of Affinity Propagation with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` + The algorithmic complexity of affinity propagation is quadratic in the number of points. From bb1b72bfd6d625770ca3059042da75f8aecd38ec Mon Sep 17 00:00:00 2001 From: SuccessMoses Date: Mon, 21 Oct 2024 13:37:53 -0700 Subject: [PATCH 02/12] DOC Linked examples for Spectral Clustering in thier docs --- sklearn/cluster/_spectral.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sklearn/cluster/_spectral.py b/sklearn/cluster/_spectral.py index ebfeccee677a9..19a29afb9f022 100644 --- a/sklearn/cluster/_spectral.py +++ b/sklearn/cluster/_spectral.py @@ -401,6 +401,9 @@ class SpectralClustering(ClusterMixin, BaseEstimator): Read more in the :ref:`User Guide `. + For a comparison of Spectral clustering with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` + Parameters ---------- n_clusters : int, default=8 From ce19dc75c5d94c7794e19060834186660cd99c0c Mon Sep 17 00:00:00 2001 From: SuccessMoses Date: Mon, 21 Oct 2024 13:56:46 -0700 Subject: [PATCH 03/12] DOC Linked examples for DBSCAN in thier docs --- sklearn/cluster/_dbscan.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sklearn/cluster/_dbscan.py b/sklearn/cluster/_dbscan.py index 7764bff94582f..58044d96ae8ed 100644 --- a/sklearn/cluster/_dbscan.py +++ b/sklearn/cluster/_dbscan.py @@ -192,6 +192,9 @@ class DBSCAN(ClusterMixin, BaseEstimator): Read more in the :ref:`User Guide `. + For a comparison of DBSCAN with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` + Parameters ---------- eps : float, default=0.5 From 9dca5984086b6d60407dbe6ff0ee466af5399ad7 Mon Sep 17 00:00:00 2001 From: SuccessMoses Date: Mon, 21 Oct 2024 14:03:13 -0700 Subject: [PATCH 04/12] DOC Linked examples for HDBSCAN in docstring --- sklearn/cluster/_hdbscan/hdbscan.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sklearn/cluster/_hdbscan/hdbscan.py b/sklearn/cluster/_hdbscan/hdbscan.py index 8bf402a5081c9..c6111898a3ead 100644 --- a/sklearn/cluster/_hdbscan/hdbscan.py +++ b/sklearn/cluster/_hdbscan/hdbscan.py @@ -433,10 +433,13 @@ class HDBSCAN(ClusterMixin, BaseEstimator): This allows HDBSCAN to find clusters of varying densities (unlike :class:`~sklearn.cluster.DBSCAN`), and be more robust to parameter selection. Read more in the :ref:`User Guide `. + + For an example of how to use HDBSCAN, as well as a comaprison to + :class:`~sklearn.cluster.DBSCAN`, please see the + :ref:`sphx_glr_auto_examples_cluster_plot_hdbscan.py` - For an example of how to use HDBSCAN, as well as a comparison to - :class:`~sklearn.cluster.DBSCAN`, please see the :ref:`plotting demo - `. + For a comparison of HDBSCAN with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` .. versionadded:: 1.3 From 3f3cfed0926e34d8716c2021cbadb3a78463ca5d Mon Sep 17 00:00:00 2001 From: SuccessMoses Date: Mon, 21 Oct 2024 14:06:12 -0700 Subject: [PATCH 05/12] DOC Linked examples for OPTICS in docstrings --- sklearn/cluster/_optics.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sklearn/cluster/_optics.py b/sklearn/cluster/_optics.py index 3b72dba4aae1b..f30b76c15ec36 100755 --- a/sklearn/cluster/_optics.py +++ b/sklearn/cluster/_optics.py @@ -57,6 +57,9 @@ class OPTICS(ClusterMixin, BaseEstimator): Read more in the :ref:`User Guide `. + For a comparison of OPTICS with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` + Parameters ---------- min_samples : int > 1 or float between 0 and 1, default=5 From 34ec6aa4b3e6494a8968f3194b75a28a542c9ae1 Mon Sep 17 00:00:00 2001 From: SuccessMoses Date: Tue, 22 Oct 2024 14:50:43 -0700 Subject: [PATCH 06/12] Reformattted with black --- sklearn/cluster/_hdbscan/hdbscan.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearn/cluster/_hdbscan/hdbscan.py b/sklearn/cluster/_hdbscan/hdbscan.py index c6111898a3ead..206f7cdbb6a65 100644 --- a/sklearn/cluster/_hdbscan/hdbscan.py +++ b/sklearn/cluster/_hdbscan/hdbscan.py @@ -433,9 +433,9 @@ class HDBSCAN(ClusterMixin, BaseEstimator): This allows HDBSCAN to find clusters of varying densities (unlike :class:`~sklearn.cluster.DBSCAN`), and be more robust to parameter selection. Read more in the :ref:`User Guide `. - + For an example of how to use HDBSCAN, as well as a comaprison to - :class:`~sklearn.cluster.DBSCAN`, please see the + :class:`~sklearn.cluster.DBSCAN`, please see the :ref:`sphx_glr_auto_examples_cluster_plot_hdbscan.py` For a comparison of HDBSCAN with other clustering algorithms, see From e7a7b41de6dab6e332503eb7ff37b58aa57ec72e Mon Sep 17 00:00:00 2001 From: SuccessMoses Date: Tue, 29 Oct 2024 22:43:31 +0100 Subject: [PATCH 07/12] move examples below example section --- sklearn/cluster/_affinity_propagation.py | 12 ++++++------ sklearn/cluster/_agglomerative.py | 3 +++ sklearn/cluster/_birch.py | 3 +++ sklearn/cluster/_dbscan.py | 12 ++++++------ sklearn/cluster/_hdbscan/hdbscan.py | 14 +++++++------- sklearn/cluster/_kmeans.py | 3 +++ sklearn/cluster/_mean_shift.py | 3 +++ sklearn/cluster/_optics.py | 6 +++--- sklearn/cluster/_spectral.py | 6 +++--- sklearn/mixture/_gaussian_mixture.py | 3 +++ 10 files changed, 40 insertions(+), 25 deletions(-) diff --git a/sklearn/cluster/_affinity_propagation.py b/sklearn/cluster/_affinity_propagation.py index 020fde1f3db8b..25cdb2111f132 100644 --- a/sklearn/cluster/_affinity_propagation.py +++ b/sklearn/cluster/_affinity_propagation.py @@ -398,12 +398,6 @@ class AffinityPropagation(ClusterMixin, BaseEstimator): Notes ----- - For an example usage, - see :ref:`sphx_glr_auto_examples_cluster_plot_affinity_propagation.py`. - - For a comparison of Affinity Propagation with other clustering algorithms, see - :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` - The algorithmic complexity of affinity propagation is quadratic in the number of points. @@ -445,6 +439,12 @@ class AffinityPropagation(ClusterMixin, BaseEstimator): >>> clustering.cluster_centers_ array([[1, 2], [4, 2]]) + + For a comparison of Affinity Propagation with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` + + For an example usage, + see :ref:`sphx_glr_auto_examples_cluster_plot_affinity_propagation.py`. """ _parameter_constraints: dict = { diff --git a/sklearn/cluster/_agglomerative.py b/sklearn/cluster/_agglomerative.py index 4dd8b57364301..7f40d547dacb4 100644 --- a/sklearn/cluster/_agglomerative.py +++ b/sklearn/cluster/_agglomerative.py @@ -930,6 +930,9 @@ class AgglomerativeClustering(ClusterMixin, BaseEstimator): AgglomerativeClustering() >>> clustering.labels_ array([1, 1, 1, 0, 0, 0]) + + For a comparison of Agglomerative clustering with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` """ _parameter_constraints: dict = { diff --git a/sklearn/cluster/_birch.py b/sklearn/cluster/_birch.py index 3e5f9d10a79e8..32414a5fa5b27 100644 --- a/sklearn/cluster/_birch.py +++ b/sklearn/cluster/_birch.py @@ -483,6 +483,9 @@ class Birch( Birch(n_clusters=None) >>> brc.predict(X) array([0, 0, 0, 1, 1, 1]) + + For a comparison of BIRCH clustering algorithm with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` """ _parameter_constraints: dict = { diff --git a/sklearn/cluster/_dbscan.py b/sklearn/cluster/_dbscan.py index 58044d96ae8ed..94a797cd858b3 100644 --- a/sklearn/cluster/_dbscan.py +++ b/sklearn/cluster/_dbscan.py @@ -192,9 +192,6 @@ class DBSCAN(ClusterMixin, BaseEstimator): Read more in the :ref:`User Guide `. - For a comparison of DBSCAN with other clustering algorithms, see - :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` - Parameters ---------- eps : float, default=0.5 @@ -280,9 +277,6 @@ class DBSCAN(ClusterMixin, BaseEstimator): Notes ----- - For an example, see - :ref:`sphx_glr_auto_examples_cluster_plot_dbscan.py`. - This implementation bulk-computes all neighborhood queries, which increases the memory complexity to O(n.d) where d is the average number of neighbors, while original DBSCAN had memory complexity O(n). It may attract a higher @@ -325,6 +319,12 @@ class DBSCAN(ClusterMixin, BaseEstimator): array([ 0, 0, 0, 1, 1, -1]) >>> clustering DBSCAN(eps=3, min_samples=2) + + For a comparison of DBSCAN with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` + + For an example, see + :ref:`sphx_glr_auto_examples_cluster_plot_dbscan.py`. """ _parameter_constraints: dict = { diff --git a/sklearn/cluster/_hdbscan/hdbscan.py b/sklearn/cluster/_hdbscan/hdbscan.py index 206f7cdbb6a65..6b41fbfe7fde9 100644 --- a/sklearn/cluster/_hdbscan/hdbscan.py +++ b/sklearn/cluster/_hdbscan/hdbscan.py @@ -434,13 +434,6 @@ class HDBSCAN(ClusterMixin, BaseEstimator): :class:`~sklearn.cluster.DBSCAN`), and be more robust to parameter selection. Read more in the :ref:`User Guide `. - For an example of how to use HDBSCAN, as well as a comaprison to - :class:`~sklearn.cluster.DBSCAN`, please see the - :ref:`sphx_glr_auto_examples_cluster_plot_hdbscan.py` - - For a comparison of HDBSCAN with other clustering algorithms, see - :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` - .. versionadded:: 1.3 Parameters @@ -638,6 +631,13 @@ class HDBSCAN(ClusterMixin, BaseEstimator): HDBSCAN(min_cluster_size=20) >>> hdb.labels_ array([ 2, 6, -1, ..., -1, -1, -1]) + + For an example of how to use HDBSCAN, as well as a comaprison to + :class:`~sklearn.cluster.DBSCAN`, please see the + :ref:`sphx_glr_auto_examples_cluster_plot_hdbscan.py` + + For a comparison of HDBSCAN with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` """ _parameter_constraints = { diff --git a/sklearn/cluster/_kmeans.py b/sklearn/cluster/_kmeans.py index 80958f8c845a2..2cc680e9b6c5d 100644 --- a/sklearn/cluster/_kmeans.py +++ b/sklearn/cluster/_kmeans.py @@ -1872,6 +1872,9 @@ class MiniBatchKMeans(_BaseKMeans): [1.06896552, 1. ]]) >>> kmeans.predict([[0, 0], [4, 4]]) array([1, 0], dtype=int32) + + For a comparison of Mini-Batch K-Means clustering with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` """ _parameter_constraints: dict = { diff --git a/sklearn/cluster/_mean_shift.py b/sklearn/cluster/_mean_shift.py index 5190936e6e39a..c122692cd0c2a 100644 --- a/sklearn/cluster/_mean_shift.py +++ b/sklearn/cluster/_mean_shift.py @@ -432,6 +432,9 @@ class MeanShift(ClusterMixin, BaseEstimator): array([1, 0]) >>> clustering MeanShift(bandwidth=2) + + For a comparison of Mean Shift clustering with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` """ _parameter_constraints: dict = { diff --git a/sklearn/cluster/_optics.py b/sklearn/cluster/_optics.py index d5019048fafdb..9518e5a00620f 100755 --- a/sklearn/cluster/_optics.py +++ b/sklearn/cluster/_optics.py @@ -57,9 +57,6 @@ class OPTICS(ClusterMixin, BaseEstimator): Read more in the :ref:`User Guide `. - For a comparison of OPTICS with other clustering algorithms, see - :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` - Parameters ---------- min_samples : int > 1 or float between 0 and 1, default=5 @@ -243,6 +240,9 @@ class OPTICS(ClusterMixin, BaseEstimator): For a more detailed example see :ref:`sphx_glr_auto_examples_cluster_plot_optics.py`. + + For a comparison of OPTICS with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` """ _parameter_constraints: dict = { diff --git a/sklearn/cluster/_spectral.py b/sklearn/cluster/_spectral.py index 19a29afb9f022..04fbe3ae57186 100644 --- a/sklearn/cluster/_spectral.py +++ b/sklearn/cluster/_spectral.py @@ -401,9 +401,6 @@ class SpectralClustering(ClusterMixin, BaseEstimator): Read more in the :ref:`User Guide `. - For a comparison of Spectral clustering with other clustering algorithms, see - :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` - Parameters ---------- n_clusters : int, default=8 @@ -604,6 +601,9 @@ class SpectralClustering(ClusterMixin, BaseEstimator): >>> clustering SpectralClustering(assign_labels='discretize', n_clusters=2, random_state=0) + + For a comparison of Spectral clustering with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` """ _parameter_constraints: dict = { diff --git a/sklearn/mixture/_gaussian_mixture.py b/sklearn/mixture/_gaussian_mixture.py index 98ade2089e273..a3a1e29d66353 100644 --- a/sklearn/mixture/_gaussian_mixture.py +++ b/sklearn/mixture/_gaussian_mixture.py @@ -687,6 +687,9 @@ class GaussianMixture(BaseMixture): [ 1., 2.]]) >>> gm.predict([[0, 0], [12, 3]]) array([1, 0]) + + For a comparison of Gaussian Mixture with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` """ _parameter_constraints: dict = { From c4a6d666781357220de05ca8edfb3f7a87a1c59c Mon Sep 17 00:00:00 2001 From: SuccessMoses Date: Tue, 29 Oct 2024 22:44:15 +0100 Subject: [PATCH 08/12] add rubric "examples" --- doc/modules/clustering.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/modules/clustering.rst b/doc/modules/clustering.rst index 7cf593baf20d1..55c88095fa1f1 100644 --- a/doc/modules/clustering.rst +++ b/doc/modules/clustering.rst @@ -140,6 +140,11 @@ model with equal covariance per component. :term:`inductive` clustering methods) are not designed to be applied to new, unseen data. +.. rubric:: Examples + +* :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py`: Shows the + characteristics of different clustering algorithms of 2D datasets. + .. _k_means: K-means From 07eb7f011748027348bbaae454fe7dc146f94e48 Mon Sep 17 00:00:00 2001 From: SuccessMoses Date: Tue, 29 Oct 2024 22:49:25 +0100 Subject: [PATCH 09/12] fix issues with ruff --- sklearn/cluster/_kmeans.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearn/cluster/_kmeans.py b/sklearn/cluster/_kmeans.py index 2cc680e9b6c5d..ae18320a0ba04 100644 --- a/sklearn/cluster/_kmeans.py +++ b/sklearn/cluster/_kmeans.py @@ -1873,8 +1873,8 @@ class MiniBatchKMeans(_BaseKMeans): >>> kmeans.predict([[0, 0], [4, 4]]) array([1, 0], dtype=int32) - For a comparison of Mini-Batch K-Means clustering with other clustering algorithms, see - :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` + For a comparison of Mini-Batch K-Means clustering with other clustering algorithms, + see :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` """ _parameter_constraints: dict = { From afcf7b79eb1ca0533ddf3d9c44c6e8fd1c3cd47c Mon Sep 17 00:00:00 2001 From: SuccessMoses Date: Thu, 31 Oct 2024 10:57:51 +0100 Subject: [PATCH 10/12] fix stuff here and there --- doc/modules/clustering.rst | 2 +- sklearn/cluster/_affinity_propagation.py | 6 +++--- sklearn/cluster/_birch.py | 2 +- sklearn/cluster/_dbscan.py | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/modules/clustering.rst b/doc/modules/clustering.rst index 55c88095fa1f1..793ac0131842e 100644 --- a/doc/modules/clustering.rst +++ b/doc/modules/clustering.rst @@ -143,7 +143,7 @@ unseen data. .. rubric:: Examples * :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py`: Shows the - characteristics of different clustering algorithms of 2D datasets. + characteristics of different clustering algorithms on 2D datasets. .. _k_means: diff --git a/sklearn/cluster/_affinity_propagation.py b/sklearn/cluster/_affinity_propagation.py index 25cdb2111f132..1b615cd7e6e66 100644 --- a/sklearn/cluster/_affinity_propagation.py +++ b/sklearn/cluster/_affinity_propagation.py @@ -440,11 +440,11 @@ class AffinityPropagation(ClusterMixin, BaseEstimator): array([[1, 2], [4, 2]]) - For a comparison of Affinity Propagation with other clustering algorithms, see - :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` - For an example usage, see :ref:`sphx_glr_auto_examples_cluster_plot_affinity_propagation.py`. + + For a comparison of Affinity Propagation with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` """ _parameter_constraints: dict = { diff --git a/sklearn/cluster/_birch.py b/sklearn/cluster/_birch.py index 32414a5fa5b27..38655b9c4f598 100644 --- a/sklearn/cluster/_birch.py +++ b/sklearn/cluster/_birch.py @@ -484,7 +484,7 @@ class Birch( >>> brc.predict(X) array([0, 0, 0, 1, 1, 1]) - For a comparison of BIRCH clustering algorithm with other clustering algorithms, see + For a comparison of the BIRCH clustering algorithm with other clustering algorithms, see :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` """ diff --git a/sklearn/cluster/_dbscan.py b/sklearn/cluster/_dbscan.py index 94a797cd858b3..ce4fcc11643e4 100644 --- a/sklearn/cluster/_dbscan.py +++ b/sklearn/cluster/_dbscan.py @@ -320,11 +320,11 @@ class DBSCAN(ClusterMixin, BaseEstimator): >>> clustering DBSCAN(eps=3, min_samples=2) - For a comparison of DBSCAN with other clustering algorithms, see - :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` - For an example, see :ref:`sphx_glr_auto_examples_cluster_plot_dbscan.py`. + + For a comparison of DBSCAN with other clustering algorithms, see + :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` """ _parameter_constraints: dict = { From 56a7d6dfe532a71207246adb910499aefc4d4f7e Mon Sep 17 00:00:00 2001 From: SuccessMoses Date: Thu, 31 Oct 2024 17:37:38 +0100 Subject: [PATCH 11/12] fix lint --- sklearn/cluster/_birch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearn/cluster/_birch.py b/sklearn/cluster/_birch.py index 38655b9c4f598..ab14619eb9fd3 100644 --- a/sklearn/cluster/_birch.py +++ b/sklearn/cluster/_birch.py @@ -484,8 +484,8 @@ class Birch( >>> brc.predict(X) array([0, 0, 0, 1, 1, 1]) - For a comparison of the BIRCH clustering algorithm with other clustering algorithms, see - :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` + For a comparison of the BIRCH clustering algorithm with other clustering algorithms, + see :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py` """ _parameter_constraints: dict = { From 2a34caaa11d0f5b405b270871e952dc431a4107b Mon Sep 17 00:00:00 2001 From: Maren Westermann Date: Sun, 16 Feb 2025 12:50:59 +0100 Subject: [PATCH 12/12] remove examples rubric --- doc/modules/clustering.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/modules/clustering.rst b/doc/modules/clustering.rst index cfd2adcddf35c..81773ed90799f 100644 --- a/doc/modules/clustering.rst +++ b/doc/modules/clustering.rst @@ -140,11 +140,6 @@ model with equal covariance per component. :term:`inductive` clustering methods) are not designed to be applied to new, unseen data. -.. rubric:: Examples - -* :ref:`sphx_glr_auto_examples_cluster_plot_cluster_comparison.py`: Shows the - characteristics of different clustering algorithms on 2D datasets. - .. _k_means: K-means