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

Method test_model_reduce

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

Source from the content-addressed store, hash-verified

676 print "pattern.vector.LSA.transform()"
677
678 def test_model_reduce(self):
679 try:
680 import numpy
681 except ImportError:
682 return
683 # Test time and accuracy of model with sparse vectors of maximum 250 features.
684 t1 = time.time()
685 A1, P1, R1, F1 = vector.KNN.test(self.model, folds=10)
686 t1 = time.time() - t1
687 # Test time and accuracy of model with reduced vectors of 20 features.
688 self.model.reduce(dimensions=20)
689 t2 = time.time()
690 A2, P2, R2, F2 = vector.KNN.test(self.model, folds=10)
691 t2 = time.time() - t2
692 self.assertTrue(len(self.model.lsa[self.model.documents[0].id]) == 20)
693 self.assertTrue(t2 * 2 < t1) # KNN over 2x faster.
694 self.assertTrue(abs(F1-F2) < 0.06) # Difference in F-score = 1-6%.
695 self.model.lsa = None
696 print "pattern.vector.Model.reduce()"
697
698#---------------------------------------------------------------------------------------------------
699

Callers

nothing calls this directly

Calls 3

lenFunction · 0.85
testMethod · 0.80
absFunction · 0.50

Tested by

no test coverage detected