Created
August 2, 2024 19:20
-
-
Save jeanmidevacc/a00c9cf8fe9379cd8a818b1d842dbaa1 to your computer and use it in GitHub Desktop.
This file contains 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
import surprise | |
# there is pandas dataframe that contains the different ratings between user and item , indexed | |
# Build a reader | |
reader = surprise.Reader(rating_scale=(dfp_actions["rating"].min(),dfp_actions["rating"].max())) | |
#_id column are index id of the user and item | |
surprise_data = surprise.Dataset.load_from_df(dfp_actions[["user_id", "item_id", "rating"]], reader = reader) | |
train_set = surprise_train.build_full_trainset() | |
params = { | |
"n_factors" : 2, | |
"n_epochs" : 21, | |
"biased" : True, | |
"reg_pu" : 36, | |
'reg_qi' : 57 | |
} | |
model = surprise.prediction_algorithms.matrix_factorization.NMF(**params) | |
model = model.fit(train_set) | |
# Get the rating for a paur user item | |
model.predict(user_id, item_id).est |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment