def test_item_model(self): tfidf = TFIDFModel("desc") tfidf.fit(self.df) self.assertAlmostEqual(tfidf._sim(1, 1), 1, places=2) self.assertAlmostEqual(tfidf._sim(100, 100), 1, places=2) self.assertGreater(tfidf._sim(1, 1), tfidf._sim(1, 100), "similarities do not make sense")
def test_get_score(self): tfidf = TFIDFModel("desc") tfidf.fit(self.df) tfidf.k = 1 #the closes item to 1 (in user 10 profile) is 100, so the score should be equal to the similarity self.assertAlmostEqual(tfidf.get_score(10, 1), tfidf._sim(100, 1), places=2)