Exemple #1
0
 def test_cosine_similarity_subset(self):
   value = rating_utils._cosine_similarity({1, 2}, {1})
   self.assertAlmostEqual(1 / math.sqrt(2), value)
Exemple #2
0
 def test_cosine_similarity_intersection(self):
   value = rating_utils._cosine_similarity({1, 2}, {2, 3})
   self.assertAlmostEqual(0.5, value)
Exemple #3
0
 def test_cosine_similarity_disjoint_sets(self):
   value = rating_utils._cosine_similarity({1}, {2, 3})
   self.assertAlmostEqual(0, value)
Exemple #4
0
 def test_cosine_similarity_equal_sets(self):
   value = rating_utils._cosine_similarity({2, 3}, {2, 3})
   self.assertAlmostEqual(1, value)
Exemple #5
0
 def test_cosine_similarity_one_empty(self):
   value = rating_utils._cosine_similarity({1}, set())
   self.assertAlmostEqual(0, value)