Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jfkirk/5cde24b42ef436818a5688aae2059e06 to your computer and use it in GitHub Desktop.
Save jfkirk/5cde24b42ef436818a5688aae2059e06 to your computer and use it in GitHub Desktop.
# 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