Skip to content

Commit 5e4a2d1

Browse files
Adding test coverage for Covariance
And storing the input data used for fit()
1 parent ac63da5 commit 5e4a2d1

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ build/
33
dist/
44
*.egg-info
55
.coverage
6+
htmlcov/

metric_learn/covariance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ def fit(self, X, y=None):
2626
X: data matrix, (n x d)
2727
y: unused, optional
2828
"""
29+
self.X = X
2930
self.M = np.cov(X.T)
3031
return self

test/metric_learn_test.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from numpy.testing import assert_array_almost_equal
77

88
from metric_learn import (
9-
LMNN, NCA, LFDA,
9+
LMNN, NCA, LFDA, Covariance,
1010
LSML_Supervised, ITML_Supervised, SDML_Supervised, RCA_Supervised)
1111
# Import this specially for testing.
1212
from metric_learn.lmnn import python_LMNN
@@ -32,6 +32,16 @@ def setUpClass(self):
3232
np.random.seed(1234)
3333

3434

35+
class TestCovariance(MetricTestCase):
36+
def test_iris(self):
37+
cov = Covariance()
38+
cov.fit(self.iris_points)
39+
40+
csep = class_separation(cov.transform(), self.iris_labels)
41+
# deterministic result
42+
self.assertAlmostEqual(csep, 0.73068122)
43+
44+
3545
class TestLSML(MetricTestCase):
3646
def test_iris(self):
3747
lsml = LSML_Supervised(num_constraints=200)

0 commit comments

Comments
 (0)