Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 59048f9

Browse files
authored
FIX Update pairwise distance function argument names (scikit-learn#26351)
1 parent 07f6586 commit 59048f9

File tree

4 files changed

+52
-52
lines changed

4 files changed

+52
-52
lines changed

sklearn/metrics/_pairwise_distances_reduction/_argkmin_classmode.pyx.tp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ cdef class ArgKminClassMode{{name_suffix}}(ArgKmin{{name_suffix}}):
2525
{{name_suffix}}bit implementation of ArgKminClassMode.
2626
"""
2727
cdef:
28-
const intp_t[:] class_membership,
29-
const intp_t[:] unique_labels
28+
const intp_t[:] Y_labels,
29+
const intp_t[:] unique_Y_labels
3030
float64_t[:, :] class_scores
3131
cpp_map[intp_t, intp_t] labels_to_index
3232
WeightingStrategy weight_type
@@ -38,14 +38,14 @@ cdef class ArgKminClassMode{{name_suffix}}(ArgKmin{{name_suffix}}):
3838
Y,
3939
intp_t k,
4040
weights,
41-
class_membership,
42-
unique_labels,
41+
Y_labels,
42+
unique_Y_labels,
4343
str metric="euclidean",
4444
chunk_size=None,
4545
dict metric_kwargs=None,
4646
str strategy=None,
4747
):
48-
"""Compute the argkmin reduction with class_membership.
48+
"""Compute the argkmin reduction with Y_labels.
4949

5050
This classmethod is responsible for introspecting the arguments
5151
values to dispatch to the most appropriate implementation of
@@ -66,8 +66,8 @@ cdef class ArgKminClassMode{{name_suffix}}(ArgKmin{{name_suffix}}):
6666
chunk_size=chunk_size,
6767
strategy=strategy,
6868
weights=weights,
69-
class_membership=class_membership,
70-
unique_labels=unique_labels,
69+
Y_labels=Y_labels,
70+
unique_Y_labels=unique_Y_labels,
7171
)
7272

7373
# Limit the number of threads in second level of nested parallelism for BLAS
@@ -83,8 +83,8 @@ cdef class ArgKminClassMode{{name_suffix}}(ArgKmin{{name_suffix}}):
8383
def __init__(
8484
self,
8585
DatasetsPair{{name_suffix}} datasets_pair,
86-
const intp_t[:] class_membership,
87-
const intp_t[:] unique_labels,
86+
const intp_t[:] Y_labels,
87+
const intp_t[:] unique_Y_labels,
8888
chunk_size=None,
8989
strategy=None,
9090
intp_t k=1,
@@ -103,15 +103,15 @@ cdef class ArgKminClassMode{{name_suffix}}(ArgKmin{{name_suffix}}):
103103
self.weight_type = WeightingStrategy.distance
104104
else:
105105
self.weight_type = WeightingStrategy.callable
106-
self.class_membership = class_membership
106+
self.Y_labels = Y_labels
107107

108-
self.unique_labels = unique_labels
108+
self.unique_Y_labels = unique_Y_labels
109109

110110
cdef intp_t idx, neighbor_class_idx
111111
# Map from set of unique labels to their indices in `class_scores`
112112
# Buffer used in building a histogram for one-pass weighted mode
113113
self.class_scores = np.zeros(
114-
(self.n_samples_X, unique_labels.shape[0]), dtype=np.float64,
114+
(self.n_samples_X, unique_Y_labels.shape[0]), dtype=np.float64,
115115
)
116116

117117
def _finalize_results(self):
@@ -142,7 +142,7 @@ cdef class ArgKminClassMode{{name_suffix}}(ArgKmin{{name_suffix}}):
142142
if use_distance_weighting:
143143
score_incr = 1 / distances[neighbor_rank]
144144
neighbor_idx = indices[neighbor_rank]
145-
neighbor_class_idx = self.class_membership[neighbor_idx]
145+
neighbor_class_idx = self.Y_labels[neighbor_idx]
146146
self.class_scores[sample_index][neighbor_class_idx] += score_incr
147147
return
148148

sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def is_usable_for(cls, X, Y, metric) -> bool:
456456
The input array to be labelled.
457457
458458
Y : ndarray of shape (n_samples_Y, n_features)
459-
The input array whose labels are provided through the `labels`
459+
The input array whose labels are provided through the `Y_labels`
460460
parameter.
461461
462462
metric : str, default='euclidean'
@@ -484,8 +484,8 @@ def compute(
484484
Y,
485485
k,
486486
weights,
487-
labels,
488-
unique_labels,
487+
Y_labels,
488+
unique_Y_labels,
489489
metric="euclidean",
490490
chunk_size=None,
491491
metric_kwargs=None,
@@ -499,23 +499,23 @@ def compute(
499499
The input array to be labelled.
500500
501501
Y : ndarray of shape (n_samples_Y, n_features)
502-
The input array whose labels are provided through the `labels`
503-
parameter.
502+
The input array whose class membership are provided through the
503+
`Y_labels` parameter.
504504
505505
k : int
506506
The number of nearest neighbors to consider.
507507
508508
weights : ndarray
509-
The weights applied over the `labels` of `Y` when computing the
509+
The weights applied over the `Y_labels` of `Y` when computing the
510510
weighted mode of the labels.
511511
512-
class_membership : ndarray
512+
Y_labels : ndarray
513513
An array containing the index of the class membership of the
514514
associated samples in `Y`. This is used in labeling `X`.
515515
516-
unique_classes : ndarray
516+
unique_Y_labels : ndarray
517517
An array containing all unique indices contained in the
518-
corresponding `class_membership` array.
518+
corresponding `Y_labels` array.
519519
520520
metric : str, default='euclidean'
521521
The distance metric to use. For a list of available metrics, see
@@ -587,8 +587,8 @@ def compute(
587587
Y=Y,
588588
k=k,
589589
weights=weights,
590-
class_membership=np.array(labels, dtype=np.intp),
591-
unique_labels=np.array(unique_labels, dtype=np.intp),
590+
Y_labels=np.array(Y_labels, dtype=np.intp),
591+
unique_Y_labels=np.array(unique_Y_labels, dtype=np.intp),
592592
metric=metric,
593593
chunk_size=chunk_size,
594594
metric_kwargs=metric_kwargs,
@@ -601,8 +601,8 @@ def compute(
601601
Y=Y,
602602
k=k,
603603
weights=weights,
604-
class_membership=np.array(labels, dtype=np.intp),
605-
unique_labels=np.array(unique_labels, dtype=np.intp),
604+
Y_labels=np.array(Y_labels, dtype=np.intp),
605+
unique_Y_labels=np.array(unique_Y_labels, dtype=np.intp),
606606
metric=metric,
607607
chunk_size=chunk_size,
608608
metric_kwargs=metric_kwargs,

sklearn/metrics/tests/test_pairwise_distances_reduction.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,8 @@ def test_argkmin_classmode_factory_method_wrong_usages():
649649
metric = "manhattan"
650650

651651
weights = "uniform"
652-
labels = rng.randint(low=0, high=10, size=100)
653-
unique_labels = np.unique(labels)
652+
Y_labels = rng.randint(low=0, high=10, size=100)
653+
unique_Y_labels = np.unique(Y_labels)
654654

655655
msg = (
656656
"Only float64 or float32 datasets pairs are supported at this time, "
@@ -663,8 +663,8 @@ def test_argkmin_classmode_factory_method_wrong_usages():
663663
k=k,
664664
metric=metric,
665665
weights=weights,
666-
labels=labels,
667-
unique_labels=unique_labels,
666+
Y_labels=Y_labels,
667+
unique_Y_labels=unique_Y_labels,
668668
)
669669

670670
msg = (
@@ -678,8 +678,8 @@ def test_argkmin_classmode_factory_method_wrong_usages():
678678
k=k,
679679
metric=metric,
680680
weights=weights,
681-
labels=labels,
682-
unique_labels=unique_labels,
681+
Y_labels=Y_labels,
682+
unique_Y_labels=unique_Y_labels,
683683
)
684684

685685
with pytest.raises(ValueError, match="k == -1, must be >= 1."):
@@ -689,8 +689,8 @@ def test_argkmin_classmode_factory_method_wrong_usages():
689689
k=-1,
690690
metric=metric,
691691
weights=weights,
692-
labels=labels,
693-
unique_labels=unique_labels,
692+
Y_labels=Y_labels,
693+
unique_Y_labels=unique_Y_labels,
694694
)
695695

696696
with pytest.raises(ValueError, match="k == 0, must be >= 1."):
@@ -700,8 +700,8 @@ def test_argkmin_classmode_factory_method_wrong_usages():
700700
k=0,
701701
metric=metric,
702702
weights=weights,
703-
labels=labels,
704-
unique_labels=unique_labels,
703+
Y_labels=Y_labels,
704+
unique_Y_labels=unique_Y_labels,
705705
)
706706

707707
with pytest.raises(ValueError, match="Unrecognized metric"):
@@ -711,8 +711,8 @@ def test_argkmin_classmode_factory_method_wrong_usages():
711711
k=k,
712712
metric="wrong metric",
713713
weights=weights,
714-
labels=labels,
715-
unique_labels=unique_labels,
714+
Y_labels=Y_labels,
715+
unique_Y_labels=unique_Y_labels,
716716
)
717717

718718
with pytest.raises(
@@ -724,8 +724,8 @@ def test_argkmin_classmode_factory_method_wrong_usages():
724724
k=k,
725725
metric=metric,
726726
weights=weights,
727-
labels=labels,
728-
unique_labels=unique_labels,
727+
Y_labels=Y_labels,
728+
unique_Y_labels=unique_Y_labels,
729729
)
730730

731731
with pytest.raises(ValueError, match="ndarray is not C-contiguous"):
@@ -735,8 +735,8 @@ def test_argkmin_classmode_factory_method_wrong_usages():
735735
k=k,
736736
metric=metric,
737737
weights=weights,
738-
labels=labels,
739-
unique_labels=unique_labels,
738+
Y_labels=Y_labels,
739+
unique_Y_labels=unique_Y_labels,
740740
)
741741

742742
non_existent_weights_strategy = "non_existent_weights_strategy"
@@ -751,8 +751,8 @@ def test_argkmin_classmode_factory_method_wrong_usages():
751751
k=k,
752752
metric=metric,
753753
weights=non_existent_weights_strategy,
754-
labels=labels,
755-
unique_labels=unique_labels,
754+
Y_labels=Y_labels,
755+
unique_Y_labels=unique_Y_labels,
756756
)
757757

758758
# TODO: introduce assertions on UserWarnings once the Euclidean specialisation
@@ -1332,16 +1332,16 @@ def test_argkmin_classmode_strategy_consistent():
13321332
metric = "manhattan"
13331333

13341334
weights = "uniform"
1335-
labels = rng.randint(low=0, high=10, size=100)
1336-
unique_labels = np.unique(labels)
1335+
Y_labels = rng.randint(low=0, high=10, size=100)
1336+
unique_Y_labels = np.unique(Y_labels)
13371337
results_X = ArgKminClassMode.compute(
13381338
X=X,
13391339
Y=Y,
13401340
k=k,
13411341
metric=metric,
13421342
weights=weights,
1343-
labels=labels,
1344-
unique_labels=unique_labels,
1343+
Y_labels=Y_labels,
1344+
unique_Y_labels=unique_Y_labels,
13451345
strategy="parallel_on_X",
13461346
)
13471347
results_Y = ArgKminClassMode.compute(
@@ -1350,8 +1350,8 @@ def test_argkmin_classmode_strategy_consistent():
13501350
k=k,
13511351
metric=metric,
13521352
weights=weights,
1353-
labels=labels,
1354-
unique_labels=unique_labels,
1353+
Y_labels=Y_labels,
1354+
unique_Y_labels=unique_Y_labels,
13551355
strategy="parallel_on_Y",
13561356
)
13571357
assert_array_equal(results_X, results_Y)

sklearn/neighbors/_classification.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ def predict_proba(self, X):
329329
self._fit_X,
330330
k=self.n_neighbors,
331331
weights=self.weights,
332-
labels=self._y,
333-
unique_labels=self.classes_,
332+
Y_labels=self._y,
333+
unique_Y_labels=self.classes_,
334334
metric=metric,
335335
metric_kwargs=metric_kwargs,
336336
# `strategy="parallel_on_X"` has in practice be shown

0 commit comments

Comments
 (0)