def test_nearest_cosine_similarity(self): users = { "John": { "a": 1, "b": 2, "c": 3 }, "Sarah": { "a": 1, "b": 2, "c": 3 }, "Andrew": { "a": -1, "b": -2, "c": -3 } } nearest = similarity.nearest_cosine("John", users) self.assertEqual(nearest, [(0.0, 'Sarah'), (2.0, 'Andrew')])
def recommend(self, k): return similarity.nearest_cosine(k, self.data)[0]