Skip to content

[MRG] Quick fix of failed tests due to new scikit-learn version (0.20.0) #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion metric_learn/itml.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def fit(self, X, y, random_state=np.random):
random_state : numpy.random.RandomState, optional
If provided, controls random number generation.
"""
X, y = check_X_y(X, y)
X, y = check_X_y(X, y, ensure_min_samples=2)
num_constraints = self.num_constraints
if num_constraints is None:
num_classes = len(np.unique(y))
Expand Down
2 changes: 1 addition & 1 deletion metric_learn/lmnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def transformer(self):
class python_LMNN(_base_LMNN):

def _process_inputs(self, X, labels):
self.X_ = check_array(X, dtype=float)
self.X_ = check_array(X, dtype=float, ensure_min_samples=2)
num_pts, num_dims = self.X_.shape
unique_labels, self.label_inds_ = np.unique(labels, return_inverse=True)
if len(self.label_inds_) != num_pts:
Expand Down
2 changes: 1 addition & 1 deletion metric_learn/lsml.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def fit(self, X, y, random_state=np.random):
random_state : numpy.random.RandomState, optional
If provided, controls random number generation.
"""
X, y = check_X_y(X, y)
X, y = check_X_y(X, y, ensure_min_samples=2)
num_constraints = self.num_constraints
if num_constraints is None:
num_classes = len(np.unique(y))
Expand Down
2 changes: 1 addition & 1 deletion metric_learn/mmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def fit(self, X, y, random_state=np.random):
random_state : numpy.random.RandomState, optional
If provided, controls random number generation.
"""
X, y = check_X_y(X, y)
X, y = check_X_y(X, y, ensure_min_samples=2)
num_constraints = self.num_constraints
if num_constraints is None:
num_classes = len(np.unique(y))
Expand Down
15 changes: 8 additions & 7 deletions test/metric_learn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_iris(self):

csep = class_separation(cov.transform(), self.iris_labels)
# deterministic result
self.assertAlmostEqual(csep, 0.73068122)
self.assertAlmostEqual(csep, 0.72981476)


class TestLSML(MetricTestCase):
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_iris(self):
nca = NCA(max_iter=(100000//n), num_dims=2, tol=1e-9)
nca.fit(self.iris_points, self.iris_labels)
csep = class_separation(nca.transform(), self.iris_labels)
self.assertLess(csep, 0.15)
self.assertLess(csep, 0.20)

def test_finite_differences(self):
"""Test gradient of loss function
Expand Down Expand Up @@ -319,16 +319,17 @@ def test_iris(self):
# Full metric
mmc = MMC(convergence_threshold=0.01)
mmc.fit(self.iris_points, [a,b,c,d])
expected = [[+0.00046504, +0.00083371, -0.00111959, -0.00165265],
[+0.00083371, +0.00149466, -0.00200719, -0.00296284],
[-0.00111959, -0.00200719, +0.00269546, +0.00397881],
[-0.00165265, -0.00296284, +0.00397881, +0.00587320]]
expected = [[ 0.000514, 0.000868, -0.001195, -0.001703],
[ 0.000868, 0.001468, -0.002021, -0.002879],
[-0.001195, -0.002021, 0.002782, 0.003964],
[-0.001703, -0.002879, 0.003964, 0.005648]]
assert_array_almost_equal(expected, mmc.metric(), decimal=6)

# Diagonal metric
mmc = MMC(diagonal=True)
mmc.fit(self.iris_points, [a,b,c,d])
expected = [0, 0, 1.21045968, 1.22552608]
expected = [0, 0, 1.210220, 1.228596]

assert_array_almost_equal(np.diag(expected), mmc.metric(), decimal=6)

# Supervised Full
Expand Down