Last active
March 5, 2025 23:22
-
-
Save LouisdeBruijn/e4249e6e2dc317dccee2e3d165da4cd1 to your computer and use it in GitHub Desktop.
Recalculate item and user vectors on-the-fly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def recalculate_user(user_ratings): | |
| '''adds new user and its liked items to sparse matrix and returns recalculated recommendations''' | |
| alpha = 40 | |
| m = load_npz('sparse_user_item.npz') | |
| n_users, n_movies = m.shape | |
| ratings = [alpha for i in range(len(user_ratings))] | |
| m.data = np.hstack((m.data, ratings)) | |
| m.indices = np.hstack((m.indices, user_ratings)) | |
| m.indptr = np.hstack((m.indptr, len(m.data))) | |
| m._shape = (n_users+1, n_movies) | |
| # recommend N items to new user | |
| with open('model.sav', 'rb') as pickle_in: | |
| model = pickle.load(pickle_in) | |
| recommended, _ = zip(*model.recommend(n_users, m, recalculate_user=True)) | |
| return recommended, map_movies(recommended) |
amazing
Nice
Obligatory "I was here". Beautifully obscure and random.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code, somehow, seems to have made it onto the screen of a Barbie toy:
https://www.reddit.com/r/ProgrammerHumor/comments/1j2kv2y/