Exemplo n.º 1
0
    def test_item_user_model(self):
        tfidf = TFIDFModel("desc")
        tfidf.fit(self.df)

        self.assertEqual(tfidf._get_item_models(self.df), {1: ["oh", "god"], 100: ["car", "very", "nice"],
                                                           110: ["sky", "sky", "blue", "nice"]})
        self.assertEqual(tfidf._users, {10: set([100]), 11: set([100, 1]), 12: set([110])})
        self.assertEqual(sorted(tfidf.tfidf.keys()), sorted([100, 1, 110]))
Exemplo n.º 2
0
    def test_item_user_model(self):
        tfidf = TFIDFModel('desc')
        tfidf.fit(self.df)

        self.assertEqual(tfidf._get_item_models(self.df), {1: ['oh', 'god'],
                                                      100: ['car', 'very', 'nice'],
                                                      110: ['sky', 'sky', 'blue', 'nice']})
        self.assertEqual(tfidf._users, {10: set([100]), 11: set([100, 1]), 12: set([110])})
        self.assertEqual(sorted(tfidf.tfidf.keys()), sorted([100, 1, 110]))
Exemplo n.º 3
0
    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")
Exemplo n.º 4
0
    def test_item_user_model(self):
        tfidf = TFIDFModel("desc")
        tfidf.fit(self.df)

        self.assertEqual(
            tfidf._get_item_models(self.df), {
                1: ["oh", "god"],
                100: ["car", "very", "nice"],
                110: ["sky", "sky", "blue", "nice"]
            })
        self.assertEqual(tfidf._users, {
            10: set([100]),
            11: set([100, 1]),
            12: set([110])
        })
        self.assertEqual(sorted(tfidf.tfidf.keys()), sorted([100, 1, 110]))
Exemplo n.º 5
0
    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")
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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)