MCPcopy Index your code
hub / github.com/clips/pattern / test_tfidf

Method test_tfidf

test/test_vector.py:322–331  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

320 print "pattern.vector.Document.tf()"
321
322 def test_tfidf(self):
323 # Assert tf-idf for documents not in a model.
324 v = [[0.0, 0.4, 0.6], [0.6, 0.4, 0.0]]
325 v = [dict(enumerate(v)) for v in v]
326 m = vector.Model([vector.Document(x) for x in v], weight=vector.TFIDF)
327 v = vector.tf_idf(v)
328 self.assertEqual(sorted(m[0].vector.items()), sorted(v[0].items()))
329 self.assertAlmostEqual(v[0][2], 0.42, places=2)
330 self.assertAlmostEqual(v[1][0], 0.42, places=2)
331 print "pattern.vector.tf_idf()"
332
333 def test_cosine_similarity(self):
334 # Test cosine similarity for documents not in a model.

Callers

nothing calls this directly

Calls 1

itemsMethod · 0.45

Tested by

no test coverage detected