class LDATest(unittest.TestCase): def setUp(self): self.ldamodule1 = LDA('svd') self.ldamodule2 = SKLDA() self.data = np.random.rand(10, 10) self.labels = np.array([1, 1, 1, 2, 2, 2, 3, 3, 3, 3]) def test_fitpredict(self): np.set_printoptions(precision=4) self.ldamodule1.fit(self.data, self.labels) self.ldamodule2.fit(self.data, self.labels) testdata = np.random.rand(10, 10) # testlabels = np.array([i%10 for i in range(testdata.shape[0])]) scores = self.ldamodule1.predict_log_prob(testdata)
def test_transform(self): ldamodule = LDA(solver='svd') self.assertIsNone(ldamodule.fit(self.data, self.labels)) totransform = np.random.rand(100, 10) transformed = ldamodule.transform(totransform, 5) self.assertEqual(transformed.shape, (100, 5))
def test_fitpredicteigen(self): ldamodule = LDA(solver='eigen') self.assertIsNone(ldamodule.fit(self.data, self.labels)) testdata = np.random.rand(100, 10) # testlabels = np.array([i%10 for i in range(testdata.shape[0])]) scores = ldamodule.predict_log_prob(testdata) for scoreset in scores: for score in scoreset: self.assertLessEqual(score, 0)