8000 Add test for precomputed distance. · bennihepp/scikit-learn@cf811d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit cf811d2

Browse files
committed
Add test for precomputed distance.
1 parent 00eff77 commit cf811d2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

sklearn/neighbors/tests/test_nearest_centroid.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from sklearn.neighbors import NearestCentroid
1111
from sklearn import datasets
12+
from sklearn.metrics.pairwise import pairwise_distances
1213

1314
# toy sample
1415
X = [[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1]]
@@ -46,6 +47,13 @@ def test_classification_toy():
4647
assert_array_equal(clf.predict(T_csr), true_result)
4748

4849

50+
def test_precomputed():
51+
clf = NearestCentroid(metric="precomputed")
52+
clf.fit(X, y)
53+
S = pairwise_distances(T, clf.centroids_)
54+
assert_array_equal(clf.predict(S), true_result)
55+
56+
4957
def test_iris():
5058
"""Check consistency on dataset iris."""
5159
for metric in ('euclidean', 'cosine'):

0 commit comments

Comments
 (0)
0