4
4
from numpy .testing import assert_array_almost_equal
5
5
import pytest
6
6
from metric_learn ._util import make_context
7
- from sklearn import clone
8
7
from sklearn .cluster import DBSCAN
9
8
9
+
10
10
class IdentityBilinearMixin (BilinearMixin ):
11
11
"""A simple Identity bilinear mixin that returns an identity matrix
12
12
M as learned. Can change M for a random matrix calling random_M.
@@ -55,6 +55,7 @@ def test_check_correctness_similarity():
55
55
assert_array_almost_equal (dist1 , desired ) # score_pairs
56
56
assert_array_almost_equal (dist2 , desired ) # get_metric
57
57
58
+
58
59
def test_check_handmade_example ():
59
60
u = np .array ([0 , 1 , 2 ])
60
61
v = np .array ([3 , 4 , 5 ])
@@ -104,8 +105,8 @@ def test_score_pairs_dim():
104
105
assert mixin .score_pairs (tuples ).shape == (tuples .shape [0 ],)
105
106
context = make_context (mixin )
106
107
msg = ("3D array of formed tuples expected{}. Found 2D array "
107
- "instead:\n input={}. Reshape your data and/or use a preprocessor.\n "
108
- .format (context , tuples [1 ]))
108
+ "instead:\n input={}. Reshape your data and/or use a preprocessor.\n "
109
+ .format (context , tuples [1 ]))
109
110
with pytest .raises (ValueError ) as raised_error :
110
111
mixin .score_pairs (tuples [1 ])
111
112
assert str (raised_error .value ) == msg
@@ -122,4 +123,4 @@ def test_check_scikitlearn_compatibility():
122
123
n = 100
123
124
X = np .array ([np .random .rand (d ) for i in range (n )])
124
125
clustering = DBSCAN (metric = mixin .get_metric ())
125
- clustering .fit (X )
126
+ clustering .fit (X )
0 commit comments