Ejemplo n.º 1
0
def driver():
    '''
    Testing recommender assignment functions with Duke eateries
    '''
    (items, ratings) = SmallDukeEatsReader.getdata()
    #     print("items = ",items)
    #     print("ratings = ", ratings)

    avg = RecommenderEngine.averages(items, ratings)
    #     print("average",avg)
    if avg == correctAvg:
        print('averages works')
    else:
        print('average fails')

    for key in ratings:
        slist = RecommenderEngine.similarities(key, ratings)
        #         print(key,slist)
        r3 = RecommenderEngine.recommendations(key, items, ratings, 3)
        #         print("top",r3)

        if key == 'Sung-Hoon' and slist == correctSim:
            print('similarities works')
        elif key == 'Sung-Hoon' and slist != correctSim:
            print('similarities fails')
        if key == 'Sarah Lee' and r3 == correctRec:
            print('recommendations works')
        elif key == 'Sarah Lee' and r3 != correctRec:
            print('recommendations fails')
Ejemplo n.º 2
0
def driver():
    (items,ratings) = SmallDukeEatsReader.getdata()
    print("items = ",items)
    print("ratings = ", ratings)
    
    avg = RecommenderEngine.averages(items,ratings)
    if avg == [('DivinityCafe', 4.0), ('TheCommons', 3.0), ('Tandoor', 2.4285714285714284), ('IlForno', 1.8),
                ('FarmStead', 1.4), ('LoopPizzaGrill', 1.0), ('TheSkillet', 0.0), ('PandaExpress', -0.2), 
                ('McDonalds', -0.3333333333333333)]:
        print("averages work")
    else:
        print("averages fails")

    
    similarities = RecommenderEngine.similarities("Sung-Hoon", ratings)
    if similarities == [('Wei', 1), ('Sly one', -1), ('Melanie', -2), ('Sarah Lee', -6), ('J J', -14), ('Harry', -24), 
                        ('Nana Grace', -29)]:
        print("similarities work")
    else:
        print("similarities fails")

    recommendations = RecommenderEngine.recommendations("Sarah Lee", ["DivinityCafe", "FarmStead", "IlForno","LoopPizzaGrill", "McDonalds", "PandaExpress",
     "Tandoor", "TheCommons", "TheSkillet"], {"Sarah Lee":[3, 3, 3, 3, 0, -3, 5, 0, -3], "Melanie": 
    [5, 0, 3, 0, 1, 3, 3, 3, 1],"J J":[0, 1, 0, -1, 1, 1, 3, 0, 1], "Sly one":[5, 0, 1, 3, 0, 0, 3, 3, 3], 
    "Sung-Hoon": [0, -1, -1, 5, 1, 3, -3, 1, -3], "Nana Grace":[5, 0, 3, -5, -1, 0, 1, 3, 0], "Harry":
    [5, 3, 0, -1, -3, -5, 0, 5, 1], "Wei":[1, 1, 0, 3, -1, 0, 5, 3, 0]}, 3)
    
    if recommendations == [('Tandoor', 149.5), ('TheCommons', 128.0), ('DivinityCafe', 123.33333333333333), ('FarmStead', 69.5),
                           ('TheSkillet', 66.0), ('LoopPizzaGrill', 62.0), ('IlForno', 33.0), ('McDonalds', -69.5), ('PandaExpress', -165.0)]:
        print("recommendations work")
    else:
        print("recommendations fails")
Ejemplo n.º 3
0
def driver():
    '''(items,ratings) = SmallDukeEatsReader.getdata()
    print("items = ",items)
    print("ratings = ", ratings)'''

    avg = RecommenderEngine.averages(items, ratings)
    print("average", avg)
    slist = RecommenderEngine.similarities("student1", ratings)
    print(slist)
    for key in ratings:
        slist = RecommenderEngine.similarities(key, ratings)
        print(key, slist)

    r3 = RecommenderEngine.recommendations("student1", items, ratings, 2)
    print(r3)

    print(MovieReader.getdata()[:5])
    print(BookReader.getdata()[:5])
Ejemplo n.º 4
0
def driver():
    (items, ratings) = SmallDukeEatsReader.getdata()
    print("items = ", items)
    print("ratings = ", ratings)

    avg = RecommenderEngine.averages(items, ratings)
    print("average", avg)

    for key in ratings:
        slist = RecommenderEngine.similarities(key, ratings)
        print(key, slist)
        r3 = RecommenderEngine.recommendations(key, items, ratings, 3)
        print("top", r3)
Ejemplo n.º 5
0
def driver():
    '''
    This function uses the file SmallDukeEatsReads to test functions 
    in RecommenderEngine by outputting validation messages.
    '''

    (items, ratings) = SmallDukeEatsReader.getdata()
    print("items = ", items)  #len 9
    print("ratings = ", ratings)

    avg = RecommenderEngine.averages(items, ratings)
    print("average", avg)
    if avg == [('DivinityCafe', 4.0), ('TheCommons', 3.0),
               ('Tandoor', 2.4285714285714284), ('IlForno', 1.8),
               ('FarmStead', 1.4), ('LoopPizzaGrill', 1.0),
               ('TheSkillet', 0.0), ('PandaExpress', -0.2),
               ('McDonalds', -0.3333333333333333)]:
        print("averages works")
    else:
        print("averages fails")

    for key in ratings:
        slist = RecommenderEngine.similarities(key, ratings)
        print(key, slist)
        if key == "Sung-Hoon":
            if slist == [('Wei', 1), ('Sly one', -1), ('Melanie', -2),
                         ('Sarah Lee', -6), ('J J', -14), ('Harry', -24),
                         ('Nana Grace', -29)]:
                print("similarities works")
            else:
                print("similarities fails")
        r3 = RecommenderEngine.recommendations(key, items, ratings, 3)
        if key == "Sarah Lee":
            if r3 == [('Tandoor', 149.5), ('TheCommons', 128.0),
                      ('DivinityCafe', 123.33333333333333),
                      ('FarmStead', 69.5), ('TheSkillet', 66.0),
                      ('LoopPizzaGrill', 62.0), ('IlForno', 33.0),
                      ('McDonalds', -69.5), ('PandaExpress', -165.0)]:
                print("recommendations works")
            else:
                print("recommendations fails")
        print("top", r3)
Ejemplo n.º 6
0
def driver():

    (items, ratings) = SmallDukeEatsReader.getdata()
    print("items = ", items)
    print("ratings = ", ratings)

    avg = RecommenderEngine.averages(items, ratings)
    print("average", avg)
    answer = [('DivinityCafe', 4.0), ('TheCommons', 3.0),
              ('Tandoor', 2.4285714285714284), ('IlForno', 1.8),
              ('FarmStead', 1.4), ('LoopPizzaGrill', 1.0), ('TheSkillet', 0.0),
              ('PandaExpress', -0.2), ('McDonalds', -0.3333333333333333)]
    if avg == answer:
        print("average works")
    else:
        print("average fails")

    for key in ratings:
        slist = RecommenderEngine.similarities(key, ratings)
        print(key, slist)
        answer = [('Wei', 1), ('Sly one', -1), ('Melanie', -2),
                  ('Sarah Lee', -6), ('J J', -14), ('Harry', -24),
                  ('Nana Grace', -29)]
        if answer == slist and key == 'Sung-Hoon':
            print("similarities works")
        if answer != slist and key == 'Sung-Hoon':
            print("similarities fails")
        r3 = RecommenderEngine.recommendations(key, items, ratings, 3)
        print("top", r3)
        answer = [('Tandoor', 149.5), ('TheCommons', 128.0),
                  ('DivinityCafe', 123.33333333333333), ('FarmStead', 69.5),
                  ('TheSkillet', 66.0), ('LoopPizzaGrill', 62.0),
                  ('IlForno', 33.0), ('McDonalds', -69.5),
                  ('PandaExpress', -165.0)]
        if answer == r3 and key == 'Sarah Lee':
            print("recommendations works")
        if answer != r3 and key == 'Sarah Lee':
            print("recommendations fails")
Ejemplo n.º 7
0
def driver():

    (items, ratings) = SmallDukeEatsReader.getdata()
    print("items = ", items)
    print("ratings = ", ratings)

    avg = RecommenderEngine.averages(items, ratings)
    if avg == [('DivinityCafe', 4.0), ('TheCommons', 3.0),
               ('Tandoor', 2.4285714285714284), ('IlForno', 1.8),
               ('FarmStead', 1.4), ('LoopPizzaGrill', 1.0),
               ('TheSkillet', 0.0), ('PandaExpress', -0.2),
               ('McDonalds', -0.3333333333333333)]:
        print("AVERAGES WORKS")
    else:
        print("AVERAGES FAILS")

    print("average", avg)

    for key in ratings:
        slist = RecommenderEngine.similarities(key, ratings)
        print(key, slist)
        r3 = RecommenderEngine.recommendations(key, items, ratings, 3)
        print("top", r3)
Ejemplo n.º 8
0
Created on Nov 24, 2015

@author: ola
'''
import RecommenderEngine, json
import SimpleFoodReader
import BookReader
import MovieReader

if __name__ == "__main__":
    #(jitems,jratings) = SimpleFoodReader.getData("foodratings_example.txt")
    (jitems, jratings) = BookReader.getData("bookratings.txt")
    #(jitems,jratings) = MovieReader.getData("movieratings.txt")
    print "items = ", jitems
    print "ratings = ", jratings

    items = json.loads(jitems)
    ratings = json.loads(jratings)

    avg = RecommenderEngine.averages(items, ratings)
    print avg

    for key in ratings:
        slist = RecommenderEngine.similarities(key, ratings)
        print key, slist
        print "\t", RecommenderEngine.scores(slist, items, ratings, 1)
        print "\t", RecommenderEngine.scores(slist, items, ratings, len(slist))

    print RecommenderEngine.recommend(ratings.keys()[0], items, ratings, 5)
    #for the above test, I randomly chose a name and a count
Ejemplo n.º 9
0
Created on Nov 24, 2015

@author: ola
'''
import RecommenderEngine, json
import SimpleFoodReader
import BookReader
import MovieReader

if __name__ == "__main__":
    #(jitems,jratings) = SimpleFoodReader.getData("foodratings_example.txt")
    (jitems,jratings) = BookReader.getData("bookratings.txt")
    #(jitems,jratings) = MovieReader.getData("movieratings.txt")
    print "items = ",jitems
    print "ratings = ", jratings
    
    items = json.loads(jitems)
    ratings = json.loads(jratings)
    
    avg = RecommenderEngine.averages(items,ratings)
    print avg
     
    for key in ratings:
        slist = RecommenderEngine.similarities(key,ratings)
        print key,slist
        print "\t",RecommenderEngine.scores(slist,items,ratings,1)
        print "\t",RecommenderEngine.scores(slist,items,ratings,len(slist))
        
    print RecommenderEngine.recommend(ratings.keys()[0], items, ratings, 5)
    #for the above test, I randomly chose a name and a count
Ejemplo n.º 10
0
    for i in ratings:
        if i == name:
            person = ratings[i]
            break
    counter = 0
    for i in range(0, len(items)):
        if counter == top:
            break
        if person[i] == 0:
            tuple = (items[i], newList[i][1])
            topThree.append(tuple)
            counter += 1
    if len(topThree):
        for i in range(0, top):
            topThree.append(newList[i])
    return topThree


if __name__ == '__main__':
    name = 'Jeanice'
    items = ['lions', 'tigers', 'bears']
    ratings = dict([('Nohemi', [1, -2, 1]), ('Ines', [-2, 2, 0]),
                    ('Evelynn', [-1, -2, -1]), ('Jeanice', [1, -2, 1])])
    size = 2
    sim = RecommenderEngine.similarities(name, ratings)
    print('sim =', sim)  # Printing for your convenience

    ret = RecommenderEngine.recommendations(name, items, ratings, size)
    print(ret[0][0])
    print(ret[0][1])
Ejemplo n.º 11
0
 def test_similarities(self):
     self.assertEqual(RecommenderEngine.similarities("student1", ratings),
                      [('student2', 5), ('student3', 4)])