Created
February 19, 2021 16:45
-
-
Save pacarvalho/4ca8192f94a103de253e5005eed72822 to your computer and use it in GitHub Desktop.
Collaborative Filtering Annex to Make Predictions for an Unseen User
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
(...) | |
print('Making predictions for an unseen user...') | |
items_to_rate = [trainset.to_raw_iid(i) for i in trainset.all_items()] | |
# We will consider this user to be ID 0 since that is not a valid ID for our real users | |
user_id = 0 | |
# Make predictions | |
predictions = [] | |
for iid in items_to_rate: | |
prediction = algo.predict(user_id, iid) | |
predictions.append([int(prediction.iid), prediction.est]) | |
# Sort the prediction from best match to worst match | |
predictions.sort(key=lambda x: x[1], reverse=True) | |
# Save the results to S3 | |
bucket.put_object(Body=str(predictions), Key='predictions/' + str(user_id)) | |
(...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment