Beispiel #1
0
    def test_add_normalized_rating(self):
        """Checks that the user average is substracted from all the ratings."""
        ratings = self.get_ratings()

        Builder.add_normalized_rating(ratings)

        norm_ratings = ratings[ratings['userid'] == 3]
        self.assertAlmostEqual(norm_ratings.iloc[0]['movieid'], 0)
        self.assertAlmostEqual(norm_ratings.iloc[0]['normalized_rating'], 0.4)
        self.assertAlmostEqual(norm_ratings.iloc[1]['movieid'], 2)
        self.assertAlmostEqual(norm_ratings.iloc[1]['normalized_rating'], 0.4)
        self.assertAlmostEqual(norm_ratings.iloc[2]['movieid'], 3)
        self.assertAlmostEqual(norm_ratings.iloc[2]['normalized_rating'], 2.4)
        self.assertAlmostEqual(norm_ratings.iloc[3]['movieid'], 4)
        self.assertAlmostEqual(norm_ratings.iloc[3]['normalized_rating'], -1.6)
        self.assertAlmostEqual(norm_ratings.iloc[4]['movieid'], 5)
        self.assertAlmostEqual(norm_ratings.iloc[4]['normalized_rating'], -1.6)
Beispiel #2
0
    def test_build_similarity_model(self):
        """Checks that the similarity model is calculated correct."""
        ratings = self.get_ratings()

        model = Builder.build_similarity_model(ratings)
        self.assertIsNotNone(model)
        self.assertEqual(len(model), 15)

        # item 0 and 2 has identical ratings. Their similarity should therefore be 1.0
        self.assertAlmostEqual(model[frozenset({0, 2})], 1.0)
def user_evidence(request, userid):

    cursor = connection.cursor()
    cursor.execute('SELECT \
                        user_id, \
                        content_id,\
                        mov.title,\
                        count(case when event = \'buy\' then 1 end) as buys,\
                        count(case when event = \'details\' then 1 end) as details,\
                        count(case when event = \'moredetails\' then 1 end) as moredetails\
                    FROM \
                      public."evidenceCollector_log" log\
                    JOIN    public.movies mov \
                    ON CAST(log.content_id AS VARCHAR(50)) = CAST(mov.id AS VARCHAR(50))\
                    WHERE\
                        user_id = \'%s\'\
                    group by log.user_id, log.content_id, mov.title\
                    order by log.user_id, log.content_id' % userid)
    data = dictfetchall(cursor)
    movie_ratings = Builder.generate_implicit_ratings(data)
    Builder.save_ratings(userid, movie_ratings)

    return JsonResponse(movie_ratings, safe=False)
Beispiel #4
0
def user_evidence(request, userid):

    cursor = connection.cursor()
    cursor.execute('SELECT \
                        user_id, \
                        content_id,\
                        mov.title,\
                        count(case when event = \'buy\' then 1 end) as buys,\
                        count(case when event = \'details\' then 1 end) as details,\
                        count(case when event = \'moredetails\' then 1 end) as moredetails\
                    FROM \
                      public."evidenceCollector_log" log\
                    JOIN    public.movies mov \
                    ON CAST(log.content_id AS VARCHAR(50)) = CAST(mov.id AS VARCHAR(50))\
                    WHERE\
                        user_id = \'%s\'\
                    group by log.user_id, log.content_id, mov.title\
                    order by log.user_id, log.content_id' % userid)
    data = dictfetchall(cursor)
    movie_ratings = Builder.generate_implicit_ratings(data)
    Builder.save_ratings(userid, movie_ratings)

    return JsonResponse(movie_ratings, safe=False)
def build_similarity_model(request):
    Builder.build_item_collaborative_model()
Beispiel #6
0
def build_similarity_model(request):
    Builder.build_item_collaborative_model()