From ebb4c8525d57764e4a4b72ebb53b431f2d12985c Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Thu, 10 Apr 2025 19:26:48 +1000 Subject: [PATCH 1/4] add comment --- sklearn/metrics/pairwise.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sklearn/metrics/pairwise.py b/sklearn/metrics/pairwise.py index 3fe3db110238e..17d275d906332 100644 --- a/sklearn/metrics/pairwise.py +++ b/sklearn/metrics/pairwise.py @@ -2444,6 +2444,7 @@ def pairwise_distances( elif metric in PAIRWISE_DISTANCE_FUNCTIONS: func = PAIRWISE_DISTANCE_FUNCTIONS[metric] elif callable(metric): + # No input dimension checking done for custom metrics (left to user) func = partial( _pairwise_callable, metric=metric, From a91e6e7cd74b1a551db5cf0a8c97d3c19d4a0935 Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Fri, 11 Apr 2025 09:57:59 +1000 Subject: [PATCH 2/4] mv comment --- sklearn/metrics/pairwise.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/metrics/pairwise.py b/sklearn/metrics/pairwise.py index 17d275d906332..dc6bfb2f7fcad 100644 --- a/sklearn/metrics/pairwise.py +++ b/sklearn/metrics/pairwise.py @@ -1990,6 +1990,7 @@ def _pairwise_callable(X, Y, metric, ensure_all_finite=True, **kwds): Y, dtype=None, ensure_all_finite=ensure_all_finite, + # No input dimension checking done for custom metrics (left to user) ensure_2d=False, ) @@ -2444,7 +2445,6 @@ def pairwise_distances( elif metric in PAIRWISE_DISTANCE_FUNCTIONS: func = PAIRWISE_DISTANCE_FUNCTIONS[metric] elif callable(metric): - # No input dimension checking done for custom metrics (left to user) func = partial( _pairwise_callable, metric=metric, From a551a44c857eb84e5fe264e736ffbd9c1fe890d2 Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Mon, 14 Apr 2025 12:57:58 +1000 Subject: [PATCH 3/4] add mote --- sklearn/metrics/pairwise.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sklearn/metrics/pairwise.py b/sklearn/metrics/pairwise.py index 2edb03f1a742c..9812030790d3f 100644 --- a/sklearn/metrics/pairwise.py +++ b/sklearn/metrics/pairwise.py @@ -2404,6 +2404,10 @@ def pairwise_distances( If Y is not None, then D_{i, j} is the distance between the ith array from X and the jth array from Y. + Notes + ----- + If metric is a callable, no restrictions are placed on `X` and `Y` dimensions. + See Also -------- pairwise_distances_chunked : Performs the same calculation as this @@ -2638,7 +2642,7 @@ def pairwise_kernels( Notes ----- - If metric is 'precomputed', Y is ignored and X is returned. + If metric is a callable, no restrictions are placed on `X` and `Y` dimensions. Examples -------- From fb793c4ed77431effafcbf13e434df3e574c94d8 Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Mon, 14 Apr 2025 13:28:57 +1000 Subject: [PATCH 4/4] format --- sklearn/metrics/pairwise.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sklearn/metrics/pairwise.py b/sklearn/metrics/pairwise.py index 9812030790d3f..1a70d2e4fbcea 100644 --- a/sklearn/metrics/pairwise.py +++ b/sklearn/metrics/pairwise.py @@ -2404,10 +2404,6 @@ def pairwise_distances( If Y is not None, then D_{i, j} is the distance between the ith array from X and the jth array from Y. - Notes - ----- - If metric is a callable, no restrictions are placed on `X` and `Y` dimensions. - See Also -------- pairwise_distances_chunked : Performs the same calculation as this @@ -2416,6 +2412,10 @@ def pairwise_distances( sklearn.metrics.pairwise.paired_distances : Computes the distances between corresponding elements of two arrays. + Notes + ----- + If metric is a callable, no restrictions are placed on `X` and `Y` dimensions. + Examples -------- >>> from sklearn.metrics.pairwise import pairwise_distances