You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey,
First, thanks for providing this amazing files that helped me a lot.
I'm trying to create a recommendation system, and I was wondering how to change/remove user/items/ratings.
I've created this function to add stuff (they work):
# add a userdefaddUsers(interactions, model, users=[], user_dict={}, epoch=5, n_jobs=4):
''' Adds ratings for a user Required Input - - interactions: the matrix containg each ratings for a user/item - model: the lightfm model - users: All the user ids of the new users - user_dict: Dictionary type output containing item_id as key and item_name as value - epoch = number of epochs to run - n_jobs = number of cores used for execution Expected Output - - interactions: The new matrix containing the new user - model: The new model trained with the new user '''foruser_idinusers:
interactions.loc[user_id] =0user_dict[user_id] =interactions.shape[0] -1val= [[0foryinrange(interactions.shape[1])]
forxinrange(interactions.shape[0])]
x=sparse.csr_matrix(val)
model.fit_partial(interactions=x, epochs=epoch, num_threads=n_jobs)
returninteractions, user_dict, model#add an itemdefaddItems(interactions, model, items=[], items_dict={}, epoch=5, n_jobs=4):
foritem_id, titleinitems:
interactions[item_id] =0items_dict[item_id] =titleval= [[0foryinrange(interactions.shape[1])]
forxinrange(interactions.shape[0])]
x=sparse.csr_matrix(val)
model.fit_partial(interactions=x, epochs=epoch, num_threads=n_jobs)
returninteractions, items_dict, model#add a ratingdefaddRatings(interactions,
model,
user_dict={},
user=0,
items=[0],
ratings=[0],
epochs=30,
n_jobs=4):
''' Adds ratings for a user Required Input - - interactions: the matrix containg each ratings for a user/item - model: the lightfm model - user_dict: Dictionary type output containing item_id as key and item_name as value - user: The user id - ratings: Array of ratings for each item -> [[ item, rating ]] - epoch = number of epochs to run - n_jobs = number of cores used for execution Expected Output - - interactions: The new matrix containing new ratings - model: The new model trained with new ratings '''foritem, ratinginratings:
interactions[item][user] =ratinguindex=user_dict[user]
val= []
foruser_indexinrange(interactions.shape[0]):
val.append(interactions.loc[user].valuesifuser_index==uindexelse [0forxinrange(interactions.shape[1])])
x=sparse.csr_matrix(val)
model.fit_partial(interactions=x, epochs=epochs, num_threads=n_jobs)
returninteractions, model
All of them work !
But how can I do to remove a rating or a user.
I don't know how to do that because fit_partial method is made to add data and not to remove
And finally, I was asking myself if setting a rating to 0 would be the same as just removing it
Thanks in advance !
The text was updated successfully, but these errors were encountered:
Hey,
First, thanks for providing this amazing files that helped me a lot.
I'm trying to create a recommendation system, and I was wondering how to change/remove user/items/ratings.
I've created this function to add stuff (they work):
All of them work !
But how can I do to remove a rating or a user.
I don't know how to do that because
fit_partial
method is made to add data and not to removeAnd finally, I was asking myself if setting a rating to 0 would be the same as just removing it
Thanks in advance !
The text was updated successfully, but these errors were encountered: