Created
January 18, 2019 01:46
-
-
Save jfkirk/5cde24b42ef436818a5688aae2059e06 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
# This method converts a list of (user, item, rating, time) to a sparse matrix | |
def interactions_list_to_sparse_matrix(interactions): | |
users_column, items_column, ratings_column, _ = zip(*interactions) | |
return sparse.coo_matrix((ratings_column, (users_column, items_column)), | |
shape=(n_users, n_items)) | |
# Create sparse matrices of interaction data | |
sparse_train_ratings = interactions_list_to_sparse_matrix(train_ratings) | |
sparse_test_ratings = interactions_list_to_sparse_matrix(test_ratings) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment