(self)
| 36 | raise NotImplementedError() |
| 37 | |
| 38 | def test_recommend(self): |
| 39 | item_users = get_checker_board(50) |
| 40 | user_items = item_users.T.tocsr() |
| 41 | |
| 42 | model = self._get_model() |
| 43 | model.fit(item_users, show_progress=False) |
| 44 | |
| 45 | for userid in range(50): |
| 46 | ids, _ = model.recommend(userid, user_items[userid], N=1) |
| 47 | self.assertEqual(len(ids), 1) |
| 48 | |
| 49 | # the top item recommended should be the same as the userid: |
| 50 | # its the one withheld item for the user that is liked by |
| 51 | # all the other similar users |
| 52 | self.assertEqual(ids[0], userid) |
| 53 | |
| 54 | # try asking for more items than possible, |
| 55 | # should return only the available items |
| 56 | # https://github.com/benfred/implicit/issues/22 |
| 57 | ids, _ = model.recommend(0, user_items[0], N=10000) |
| 58 | self.assertTrue(len(ids)) |
| 59 | |
| 60 | # filter recommended items using an additional filter list |
| 61 | # https://github.com/benfred/implicit/issues/26 |
| 62 | ids, _ = model.recommend(0, user_items[0], N=1, filter_items=[0]) |
| 63 | self.assertTrue(0 not in set(ids)) |
| 64 | |
| 65 | def test_recommend_batch(self): |
| 66 | user_items = get_checker_board(50) |
nothing calls this directly
no test coverage detected