コード例 #1
0
ファイル: test_lda.py プロジェクト: qeryq/SFECOMLA
    def test_transform_changed_domain(self):
        """
        1. Open data, apply some preprocessor, splits the data into two parts,
        use LDA on the first part, and then transform the second part.

        2. Open data, split into two parts, apply the same preprocessor and
        LDA only on the first part, and then transform the second part.

        The transformed second part in (1) and (2) has to be the same.
        """
        data = Table("iris")
        data = Randomize()(data)
        preprocessor = Continuize()
        lda = LDA()

        # normalize all
        ndata = preprocessor(data)

        model = lda(ndata[:75])
        result_1 = model(ndata[75:])

        # normalize only the "training" part
        ndata = preprocessor(data[:75])
        model = lda(ndata)
        result_2 = model(data[75:])

        np.testing.assert_almost_equal(result_1.X, result_2.X)
コード例 #2
0
ファイル: test_lda.py プロジェクト: qeryq/SFECOMLA
 def test_lda(self):
     iris = Table('iris')
     n_components = 2
     lda = LDA(solver="eigen", n_components=n_components)
     model = lda(iris)
     transformed = model(iris)
     self.assertEqual(transformed.X.shape, (len(iris), n_components))
     self.assertEqual(transformed.Y.shape, (len(iris),))
コード例 #3
0
 def test_lda(self):
     iris = Table("iris")
     n_components = 2
     lda = LDA(n_components=n_components)
     model = lda(iris)
     transformed = model(iris)
     self.assertEqual(transformed.X.shape, (len(iris), n_components))
     self.assertEqual(transformed.Y.shape, (len(iris),))
コード例 #4
0
    def init_projection(self):
        if self.placement == Placement.Circular:
            self.projector = CircularPlacement()
        elif self.placement == Placement.LDA:
            self.projector = LDA(solver="eigen", n_components=2)
        elif self.placement == Placement.PCA:
            self.projector = PCA(n_components=2)
            self.projector.component = 2
            self.projector.preprocessors = PCA.preprocessors + [Normalize()]

        super().init_projection()