Beispiel #1
0
 def test_sparse_matrix(self):
     rows = Rows(TestFeatureEncoder.rows)
     fe = FeatureEncoder(rows)
     inv_idx = fe.make_sparse_matrix()
     expected = csr_matrix(((3, 2, 1, 3, 2, 1),
                            ((0, 0, 0, 1, 1, 1), (0, 1, 2, 0, 1, 3))),
                           shape=(2, 4),
                           dtype=int32)
     to_string = lambda mat: str(mat.toarray()).replace('\n', ',')
     # scipy.sparse.matrix.nnz: number of non-zero values
     self.assertEqual(abs(inv_idx - expected).nnz, 0,
                      "{} != {}".format(to_string(expected),
                                        to_string(inv_idx)))
Beispiel #2
0
 def test_sparse_matrix(self):
     rows = Rows(TestFeatureEncoder.rows)
     fe = FeatureEncoder(rows)
     inv_idx = fe.make_sparse_matrix()
     expected = csr_matrix(
         ((3, 2, 1, 3, 2, 1), ((0, 0, 0, 1, 1, 1), (0, 1, 2, 0, 1, 3))),
         shape=(2, 4),
         dtype=int32)
     to_string = lambda mat: str(mat.toarray()).replace('\n', ',')
     # scipy.sparse.matrix.nnz: number of non-zero values
     self.assertEqual(
         abs(inv_idx - expected).nnz, 0,
         "{} != {}".format(to_string(expected), to_string(inv_idx)))
Beispiel #3
0
 def test_make_vocabulary(self):
     rows = Rows(TestFeatureEncoder.rows)
     fe = FeatureEncoder(rows)
     fe.make_sparse_matrix()
     self.assertEqual({'a': 0, 'b': 1, 'c': 2, 'd': 3}, fe.vocabulary)
Beispiel #4
0
 def test_make_vocabulary(self):
     rows = Rows(TestFeatureEncoder.rows)
     fe = FeatureEncoder(rows)
     fe.make_sparse_matrix()
     self.assertEqual({'a': 0, 'b': 1, 'c': 2, 'd': 3}, fe.vocabulary)