def test_iris(self): cov = Covariance() cov.fit(self.iris_points) csep = class_separation(cov.transform(), self.iris_labels) # deterministic result self.assertAlmostEqual(csep, 0.72981476)
def test_iris(self): cov = Covariance() cov.fit(self.iris_points) csep = class_separation(cov.transform(), self.iris_labels) # deterministic result self.assertAlmostEqual(csep, 0.73068122)
def test_cov(self): cov = Covariance() cov.fit(self.X) res_1 = cov.transform(self.X) cov = Covariance() res_2 = cov.fit_transform(self.X) # deterministic result assert_array_almost_equal(res_1, res_2)
def test_cov(self): cov = Covariance() cov.fit(self.X) res_1 = cov.transform(self.X) cov = Covariance() res_2 = cov.fit_transform(self.X) # deterministic result assert_array_almost_equal(res_1, res_2)
def test_singular_returns_pseudo_inverse(self): """Checks that if the input covariance matrix is singular, we return the pseudo inverse""" X, y = load_iris(return_X_y=True) # We add a virtual column that is a linear combination of the other # columns so that the covariance matrix will be singular X = np.concatenate([X, X[:, :2].dot([[2], [3]])], axis=1) cov_matrix = np.cov(X, rowvar=False) covariance = Covariance() covariance.fit(X) pseudo_inverse = covariance.get_mahalanobis_matrix() # here is the definition of a pseudo inverse according to wikipedia: assert_allclose( cov_matrix.dot(pseudo_inverse).dot(cov_matrix), cov_matrix) assert_allclose( pseudo_inverse.dot(cov_matrix).dot(pseudo_inverse), pseudo_inverse)
def test_cov(self): cov = Covariance() cov.fit(self.X) L = cov.components_ assert_array_almost_equal(L.T.dot(L), cov.get_mahalanobis_matrix())
def train_covariance(X): model = Covariance() model.fit(X) return model.transform(X), model.metric()
def test_cov(self): cov = Covariance() cov.fit(self.X) L = cov.transformer_ assert_array_almost_equal(L.T.dot(L), cov.metric())
def test_cov(self): cov = Covariance() cov.fit(self.X) L = cov.transformer_ assert_array_almost_equal(L.T.dot(L), cov.get_mahalanobis_matrix())
def test_cov(self): cov = Covariance() cov.fit(self.X) L = cov.transformer() assert_array_almost_equal(L.T.dot(L), cov.metric())