Esempio n. 1
0
    def test_recommend(self):
        userID = "Leopoldo Pires"
        recSys = SlopeOneRecommender(self.model, True, False, False)
        self.assertEquals(["You, Me and Dupree", "Just My Luck"], recSys.recommend(userID, 4))
        recSys = SlopeOneRecommender(self.model, True, False, True)
        self.assertEquals(["You, Me and Dupree", "Just My Luck"], recSys.recommend(userID, 4))

        recSys = SlopeOneRecommender(
            DictDataModel(
                {"John": {"A": 5.0, "B": 3.0, "C": 2.0}, "Mark": {"A": 3.0, "B": 4.0}, "Lucy": {"B": 2.0, "C": 5.0}}
            ),
            True,
            False,
            False,
        )
        self.assertEquals(["A"], recSys.recommend("Lucy", 4))

        users2 = {
            "Amy": {"Dr. Dog": 4, "Lady Gaga": 3, "Phoenix": 4},
            "Ben": {"Dr. Dog": 5, "Lady Gaga": 2},
            "Clara": {"Lady Gaga": 3.5, "Phoenix": 4},
        }
        recSys = SlopeOneRecommender(DictDataModel(users2), True, False, False)
        self.assertEquals(["Phoenix"], recSys.recommend("Ben", 1))
Esempio n. 2
0
 def test_empty_recommend(self):
     userID = "Marcel Caraciolo"
     recSys = SlopeOneRecommender(self.model, True, False, False)
     self.assertEquals([], recSys.recommend(userID, 4))
     recSys = SlopeOneRecommender(self.model, True, False, True)
     self.assertEquals([], recSys.recommend(userID, 4))
Esempio n. 3
0
    def test_local_not_existing_estimatePreference(self):
        userID = "Leopoldo Pires"
        itemID = "You, Me and Dupree"
        # Weighted - With Prune
        recSys = SlopeOneRecommender(self.model, True, False, True)
        self.assertAlmostEquals(2.333333333333, recSys.estimatePreference(userID=userID, itemID=itemID))
        # Weighted - No Prune
        recSys = SlopeOneRecommender(self.model, True, False, False)
        self.assertAlmostEquals(2.333333333333, recSys.estimatePreference(userID=userID, itemID=itemID))
        # No Weighted - No Prune
        recSys = SlopeOneRecommender(self.model, False, False, False)
        self.assertAlmostEquals(2.395833333333, recSys.estimatePreference(userID=userID, itemID=itemID))
        # No Weighted - With Prune
        recSys = SlopeOneRecommender(self.model, False, False, True)
        self.assertAlmostEquals(2.39583333333, recSys.estimatePreference(userID=userID, itemID=itemID))

        # Weighted - StdDev - With Prune
        recSys = SlopeOneRecommender(self.model, True, True, True)
        self.assertAlmostEquals(2.333333333333, recSys.estimatePreference(userID=userID, itemID=itemID))
        # Weighted - StdDev - No Prune
        recSys = SlopeOneRecommender(self.model, True, True, False)
        self.assertAlmostEquals(2.333333333333, recSys.estimatePreference(userID=userID, itemID=itemID))

        # Without Prune- Weighted
        recSys = SlopeOneRecommender(
            DictDataModel(
                {"John": {"A": 5.0, "B": 3.0, "C": 2.0}, "Mark": {"A": 3.0, "B": 4.0}, "Lucy": {"B": 2.0, "C": 5.0}}
            ),
            True,
            False,
            False,
        )
        self.assertAlmostEquals(4.3333333333333, recSys.estimatePreference(userID="Lucy", itemID="A"))
Esempio n. 4
0
 def test_local_estimatePreference(self):
     userID = "Marcel Caraciolo"
     itemID = "Superman Returns"
     recSys = SlopeOneRecommender(self.model, False, False)
     self.assertAlmostEquals(3.5, recSys.estimatePreference(userID=userID, itemID=itemID))
Esempio n. 5
0
 def test_semi_recommend(self):
     userID = 'Leopoldo Pires'
     recSys = SlopeOneRecommender(self.model, True, False, False)
     self.assertEquals(['You, Me and Dupree'], recSys.recommend(userID, 1))
     recSys = SlopeOneRecommender(self.model, True, False, True)
     self.assertEquals(['You, Me and Dupree'], recSys.recommend(userID, 1))
Esempio n. 6
0
 def test_full_recommend(self):
     userID = 'Maria Gabriela'
     recSys = SlopeOneRecommender(self.model, True, False, False)
     self.assertEquals([], recSys.recommend(userID, 4))
     recSys = SlopeOneRecommender(self.model, True, False, True)
     self.assertEquals([], recSys.recommend(userID, 4))
Esempio n. 7
0
 def test_limits_AvgDistanceRecSys(self):
     evaluator = AverageAbsoluteDifferenceRecommenderEvaluator()
     recommender = SlopeOneRecommender(self.model, True, False, False)
     self.assertRaises(Exception, evaluator.evaluate, recommender,
                       self.model, 1.3, -0.3)
Esempio n. 8
0
 def test_semi_recommend(self):
     userID = "Leopoldo Pires"
     recSys = SlopeOneRecommender(self.model, True, False, False)
     self.assertEquals(["You, Me and Dupree"], recSys.recommend(userID, 1))
     recSys = SlopeOneRecommender(self.model, True, False, True)
     self.assertEquals(["You, Me and Dupree"], recSys.recommend(userID, 1))
Esempio n. 9
0
    def test_local_not_existing_estimatePreference(self):
        userID = 'Leopoldo Pires'
        itemID = 'You, Me and Dupree'
        #Weighted - With Prune
        recSys = SlopeOneRecommender(self.model, True, False, True)
        self.assertAlmostEquals(
            2.333333333333,
            recSys.estimatePreference(userID=userID, itemID=itemID))
        #Weighted - No Prune
        recSys = SlopeOneRecommender(self.model, True, False, False)
        self.assertAlmostEquals(
            2.333333333333,
            recSys.estimatePreference(userID=userID, itemID=itemID))
        #No Weighted - No Prune
        recSys = SlopeOneRecommender(self.model, False, False, False)
        self.assertAlmostEquals(
            2.395833333333,
            recSys.estimatePreference(userID=userID, itemID=itemID))
        #No Weighted - With Prune
        recSys = SlopeOneRecommender(self.model, False, False, True)
        self.assertAlmostEquals(
            2.39583333333,
            recSys.estimatePreference(userID=userID, itemID=itemID))

        #Weighted - StdDev - With Prune
        recSys = SlopeOneRecommender(self.model, True, True, True)
        self.assertAlmostEquals(
            2.333333333333,
            recSys.estimatePreference(userID=userID, itemID=itemID))
        #Weighted - StdDev - No Prune
        recSys = SlopeOneRecommender(self.model, True, True, False)
        self.assertAlmostEquals(
            2.333333333333,
            recSys.estimatePreference(userID=userID, itemID=itemID))

        #Without Prune- Weighted
        recSys = SlopeOneRecommender(
            DictDataModel({
                'John': {
                    'A': 5.0,
                    'B': 3.0,
                    'C': 2.0
                },
                'Mark': {
                    'A': 3.0,
                    'B': 4.0
                },
                'Lucy': {
                    'B': 2.0,
                    'C': 5.0
                }
            }), True, False, False)
        self.assertAlmostEquals(
            4.3333333333333,
            recSys.estimatePreference(userID='Lucy', itemID='A'))
Esempio n. 10
0
 def test_local_estimatePreference(self):
     userID = 'Marcel Caraciolo'
     itemID = 'Superman Returns'
     recSys = SlopeOneRecommender(self.model, False, False)
     self.assertAlmostEquals(
         3.5, recSys.estimatePreference(userID=userID, itemID=itemID))
Esempio n. 11
0
 def test_create_ItemBasedRecommender(self):
     recSys = SlopeOneRecommender(self.model, True, True)
     self.assertEquals(recSys.weighted, True)
     self.assertEquals(recSys.stdDevWeighted, True)
     self.assertEquals(recSys.model, self.model)
Esempio n. 12
0
 def test_limits_RMSRecommenderEvaluator(self):
     evaluator = RMSRecommenderEvaluator()
     recommender = SlopeOneRecommender(self.model, True, False, False)
     self.assertRaises(Exception, evaluator.evaluate, recommender,
                       self.model, 0, -0.3)
Esempio n. 13
0
 def test_Slope_IRStatsRecommenderEvaluator(self):
     evaluator = IRStatsRecommenderEvaluator()
     recommender = SlopeOneRecommender(self.model, True, False, False)
     result = evaluator.evaluate(recommender, self.model, 2, 1.0)
     print result
Esempio n. 14
0
 def test_Slope_RMSRecommenderEvaluator(self):
     evaluator = RMSRecommenderEvaluator()
     recommender = SlopeOneRecommender(self.model, True, False, False)
     result = evaluator.evaluate(recommender, self.model, 0.7, 1.0)
Esempio n. 15
0
 def test_empty_recommend(self):
     userID = 'Marcel Caraciolo'
     recSys = SlopeOneRecommender(self.model, True, False, False)
     self.assertEquals([], recSys.recommend(userID, 4))
     recSys = SlopeOneRecommender(self.model, True, False, True)
     self.assertEquals([], recSys.recommend(userID, 4))
Esempio n. 16
0
 def test_full_recommend(self):
     userID = "Maria Gabriela"
     recSys = SlopeOneRecommender(self.model, True, False, False)
     self.assertEquals([], recSys.recommend(userID, 4))
     recSys = SlopeOneRecommender(self.model, True, False, True)
     self.assertEquals([], recSys.recommend(userID, 4))
Esempio n. 17
0
    def test_recommend(self):
        userID = 'Leopoldo Pires'
        recSys = SlopeOneRecommender(self.model, True, False, False)
        self.assertEquals(['You, Me and Dupree', 'Just My Luck'],
                          recSys.recommend(userID, 4))
        recSys = SlopeOneRecommender(self.model, True, False, True)
        self.assertEquals(['You, Me and Dupree', 'Just My Luck'],
                          recSys.recommend(userID, 4))

        recSys = SlopeOneRecommender(
            DictDataModel({
                'John': {
                    'A': 5.0,
                    'B': 3.0,
                    'C': 2.0
                },
                'Mark': {
                    'A': 3.0,
                    'B': 4.0
                },
                'Lucy': {
                    'B': 2.0,
                    'C': 5.0
                }
            }), True, False, False)
        self.assertEquals(['A'], recSys.recommend('Lucy', 4))

        users2 = {
            "Amy": {
                "Dr. Dog": 4,
                "Lady Gaga": 3,
                "Phoenix": 4
            },
            "Ben": {
                "Dr. Dog": 5,
                "Lady Gaga": 2
            },
            "Clara": {
                "Lady Gaga": 3.5,
                "Phoenix": 4
            }
        }
        recSys = SlopeOneRecommender(DictDataModel(users2), True, False, False)
        self.assertEquals(['Phoenix'], recSys.recommend('Ben', 1))
Esempio n. 18
0
sys.path.append('/Users/marcelcaraciolo/Desktop/crab/crab/crab')

from models.datamodel import *
from recommender.recommender import SlopeOneRecommender
from recommender.utils import DiffStorage
from evaluation.statistics import *

#Load the dataset
input = open('model.pk1', 'rb')
model = pickle.load(input)
model = DictDataModel(model)

#Instantiate the Evaluator
evaluator = RMSRecommenderEvaluator()
#Instantiate the Slope One Recommender
recommender = SlopeOneRecommender(model, True, False, False)

#Calculate the Root Mean Squared Error
rmse = evaluator.evaluate(recommender, model, 0.7, 1.0)

#Instantiate the IR Stats Recommender Evaluator
evaluator = IRStatsRecommenderEvaluator()

#Calculate the Precision, Recall and F1Score
result = evaluator.evaluate(recommender, model, 25, 1.0)

#1.04078332386 0.17222222222222 0.1722222222222 0.17222222222222
print rmse, result['precision'], result['recall'], result['f1Score']

#For plotting the graph.
import scipy as sc
Esempio n. 19
0
 def test_Slope_AvgDistanceRecSys(self):
     evaluator = AverageAbsoluteDifferenceRecommenderEvaluator()
     recommender = SlopeOneRecommender(self.model, True, False, False)
     result = evaluator.evaluate(recommender, self.model, 0.7, 1.0)