From 801cec8772183746647e20c3d71c7b42aa7de70a Mon Sep 17 00:00:00 2001 From: Nicki Skafte Detlefsen Date: Tue, 15 Oct 2024 16:15:42 +0200 Subject: [PATCH] Improve CI stability for clustering examples (#2785) * Update src/torchmetrics/functional/clustering/calinski_harabasz_score.py * Update src/torchmetrics/functional/clustering/davies_bouldin_score.py --- src/torchmetrics/clustering/calinski_harabasz_score.py | 10 +++++----- .../functional/clustering/calinski_harabasz_score.py | 6 +++--- .../functional/clustering/davies_bouldin_score.py | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/torchmetrics/clustering/calinski_harabasz_score.py b/src/torchmetrics/clustering/calinski_harabasz_score.py index a9cb9df1c01..483e4332148 100644 --- a/src/torchmetrics/clustering/calinski_harabasz_score.py +++ b/src/torchmetrics/clustering/calinski_harabasz_score.py @@ -56,11 +56,11 @@ class CalinskiHarabaszScore(Metric): Example:: >>> from torch import randn, randint >>> from torchmetrics.clustering import CalinskiHarabaszScore - >>> data = randn(10, 3) - >>> labels = randint(3, (10,)) + >>> data = randn(20, 3) + >>> labels = randint(3, (20,)) >>> metric = CalinskiHarabaszScore() >>> metric(data, labels) - tensor(3.0053) + tensor(2.2128) """ @@ -108,7 +108,7 @@ def plot(self, val: Union[Tensor, Sequence[Tensor], None] = None, ax: Optional[_ >>> import torch >>> from torchmetrics.clustering import CalinskiHarabaszScore >>> metric = CalinskiHarabaszScore() - >>> metric.update(torch.randn(10, 3), torch.randint(0, 2, (10,))) + >>> metric.update(torch.randn(20, 3), torch.randint(3, (20,))) >>> fig_, ax_ = metric.plot(metric.compute()) .. plot:: @@ -120,7 +120,7 @@ def plot(self, val: Union[Tensor, Sequence[Tensor], None] = None, ax: Optional[_ >>> metric = CalinskiHarabaszScore() >>> values = [ ] >>> for _ in range(10): - ... values.append(metric(torch.randn(10, 3), torch.randint(0, 2, (10,)))) + ... values.append(metric(torch.randn(20, 3), torch.randint(3, (20,)))) >>> fig_, ax_ = metric.plot(values) """ diff --git a/src/torchmetrics/functional/clustering/calinski_harabasz_score.py b/src/torchmetrics/functional/clustering/calinski_harabasz_score.py index e28e7f9a9c3..7501ff8f15d 100644 --- a/src/torchmetrics/functional/clustering/calinski_harabasz_score.py +++ b/src/torchmetrics/functional/clustering/calinski_harabasz_score.py @@ -33,10 +33,10 @@ def calinski_harabasz_score(data: Tensor, labels: Tensor) -> Tensor: Example: >>> from torch import randn, randint >>> from torchmetrics.functional.clustering import calinski_harabasz_score - >>> data = randn(10, 3) - >>> labels = randint(0, 2, (10,)) + >>> data = randn(20, 3) + >>> labels = randint(0, 3, (20,)) >>> calinski_harabasz_score(data, labels) - tensor(3.4998) + tensor(2.2128) """ _validate_intrinsic_cluster_data(data, labels) diff --git a/src/torchmetrics/functional/clustering/davies_bouldin_score.py b/src/torchmetrics/functional/clustering/davies_bouldin_score.py index 89ee1bb5d19..1d6a7222703 100644 --- a/src/torchmetrics/functional/clustering/davies_bouldin_score.py +++ b/src/torchmetrics/functional/clustering/davies_bouldin_score.py @@ -33,10 +33,10 @@ def davies_bouldin_score(data: Tensor, labels: Tensor) -> Tensor: Example: >>> from torch import randn, randint >>> from torchmetrics.functional.clustering import davies_bouldin_score - >>> data = randn(10, 3) - >>> labels = randint(0, 2, (10,)) + >>> data = randn(20, 3) + >>> labels = randint(0, 3, (20,)) >>> davies_bouldin_score(data, labels) - tensor(1.3249) + tensor(2.7418) """ _validate_intrinsic_cluster_data(data, labels)