コード例 #1
0
ファイル: test_vector.py プロジェクト: xu-hong/pattern
 def test_tfidf(self):
     # Assert tf-idf for documents not in a corpus.
     v = [[0.0, 0.1, 0.2], [0.2, 0.1, 0.0]]
     v = vector.tf_idf(v)
     self.assertAlmostEqual(v[0][2], 0.14, places=2)
     self.assertAlmostEqual(v[1][0], 0.14, places=2)
     print "pattern.vector.tf_idf()"
コード例 #2
0
ファイル: test_vector.py プロジェクト: kracekumar/pattern
 def test_tfidf(self):
     # Assert tf-idf for documents not in a corpus.
     v = [[0.0,0.1,0.2], [0.2,0.1,0.0]]
     v = vector.tf_idf(v)
     self.assertAlmostEqual(v[0][2], 0.14, places=2)
     self.assertAlmostEqual(v[1][0], 0.14, places=2)
     print "pattern.vector.tf_idf()"
コード例 #3
0
ファイル: test_vector.py プロジェクト: andres-root/pattern
 def test_tfidf(self):
     # Assert tf-idf for documents not in a model.
     v = [[0.0, 0.4, 0.6], [0.6, 0.4, 0.0]]
     v = [dict(enumerate(v)) for v in v]
     m = vector.Model([vector.Document(x) for x in v], weight=vector.TFIDF)
     v = [vector.sparse(v) for v in vector.tf_idf(v)]
     self.assertEqual(sorted(m[0].vector.items()), sorted(v[0].items()))
     self.assertAlmostEqual(v[0][2], 0.42, places=2)
     self.assertAlmostEqual(v[1][0], 0.42, places=2)
     print("pattern.vector.tf_idf()")
コード例 #4
0
 def test_tfidf(self):
     # Assert tf-idf for documents not in a model.
     v = [[0.0, 0.4, 0.6], [0.6, 0.4, 0.0]]
     v = [dict(enumerate(v)) for v in v]
     m = vector.Model([vector.Document(x) for x in v], weight=vector.TFIDF)
     v = [vector.sparse(v) for v in vector.tf_idf(v)]
     self.assertEqual(sorted(m[0].vector.items()), sorted(v[0].items()))
     self.assertAlmostEqual(v[0][2], 0.42, places=2)
     self.assertAlmostEqual(v[1][0], 0.42, places=2)
     print("pattern.vector.tf_idf()")