def construct_pca_all_comp(self):
     pca = plinear.PCA(
         standardize=self.standardize,
         max_components=0,
         variance_covered=1,
         use_generalized_eigenvectors=self.use_generalized_eigenvectors)
     return pca
 def construct_pca(self):
     max_components = self.max_components
     variance_covered = self.variance_covered
     pca = plinear.PCA(
         standardize=self.standardize,
         max_components=max_components,
         variance_covered=variance_covered / 100.0,
         use_generalized_eigenvectors=self.use_generalized_eigenvectors)
     return pca
Exemplo n.º 3
0
    def test_can_pickle_and_unpickle(self):
        self.create_normal_dataset()
        projector = linear.PCA(variance_covered=.99)(self.dataset)

        pickled = pickle.dumps(projector)
        restored = pickle.loads(pickled)

        self.assertFalse((projector.projection - restored.projection).any())
        self.assertFalse((projector.center - restored.center).any())
        self.assertFalse((projector.scale - restored.scale).any())

        transformed, new_transformed = projector(self.dataset), restored(self.dataset)
        print transformed[0][0]
        for ex1, ex2 in zip(transformed, new_transformed):
            for v1, v2 in zip(ex1, ex2):
                self.assertEqual(v1, v2)