Exemplo n.º 1
0
 def test_repeating_spliced_data(self):
     """
     Test repeating data on the same model by splitting a dataFrame
     """
     splitter = RandomSplitter()
     for i in range(10):
         training, testing = splitter.split(self.df, 0.20)
         self.popularity.fit(training)
         for _, row in testing.iterrows():
             score = self.popularity.getScore(row["user"], row["item"])
             assert isinstance(score, float), "The result of the score is not a float"
Exemplo n.º 2
0
 def test_bpr(self):
     """
     Test the bpr okapi algorithm
     """
     splitter = RandomSplitter()
     training, testing = splitter.split(self.df, 0.20)
     bpr = BPR()
     bpr.fit(training)
     self.bpr.fit(training)
     for _, row in testing.iterrows():
         okapi_score = self.bpr.getScore(row["user"], row["item"])
         python_score = bpr.getScore(row["user"], row["item"])
         assert (
             okapi_score == python_score
         ), "Okapi bpr(%f) don't give the same score as his python implementation(%f)" % (okapi_score, python_score)
Exemplo n.º 3
0
 def test_popularity(self):
     """
     Test the popularity okapi algorithm
     """
     splitter = RandomSplitter()
     training, testing = splitter.split(self.df, 0.20)
     pop = Popularity(normalize=False)
     pop.fit(training)
     self.popularity.fit(training)
     for _, row in testing.iterrows():
         assert row["user"] in training["user"]
         python_score = pop.getScore(row["user"], row["item"])
         okapi_score = self.popularity.getScore(row["user"], row["item"])
         assert okapi_score == python_score, \
             "Okapi popularity(%f) don't give the same score as his python implementation(%f)" % (okapi_score,
                                                                                                  python_score)
Exemplo n.º 4
0
 def test_popularity(self):
     """
     Test the popularity okapi algorithm
     """
     splitter = RandomSplitter()
     training, testing = splitter.split(self.df, 0.20)
     pop = Popularity(normalize=False)
     pop.fit(training)
     self.popularity.fit(training)
     for _, row in testing.iterrows():
         assert row["user"] in training["user"]
         python_score = pop.getScore(row["user"], row["item"])
         okapi_score = self.popularity.getScore(row["user"], row["item"])
         assert okapi_score == python_score, \
             "Okapi popularity(%f) don't give the same score as his python implementation(%f)" % (okapi_score,
                                                                                                  python_score)
Exemplo n.º 5
0
class split(object):
    holdout = HoldoutSplitter()
    holdoutByRandomSlow = RandomHoldoutSplitter()
    holdoutByUser = HoldoutSplitterByUser()
    holdoutByRandom = RandomSplitter()