A user-item interaction matrix records behavior in a form a recommender can compare: each row is a user, each column is an item, and each cell represents an interaction. For comic consumption, a 1 can mean a user consumed a comic and a 0 that they did not. A ratings matrix instead holds observed ratings and leaves unknown ratings to be predicted. These encodings answer different questions: converting ratings to watch indicators retains evidence of consumption but not how much the user liked the movie. section 1.3.2 section 2.2.2 section 3.3.1
From shared comics to recommendations
In a synthetic dataset of 100 users, each user consumed one to three comics. The first user's row marks Asterix, Lucky Luke, and The Smurfs as consumed. Across all rows, Asterix and Superman were consumed together by 21 users. A user-based method compares rows to find people with overlapping histories, then scores comics those people consumed but the target user has not. An item-based method compares columns to find comics consumed by overlapping groups of users. section 1.3.2 section 1.3.2
To build a binary movie matrix, assign each user ID and movie ID a contiguous index, translate each recorded user-movie pair into a row and column, and place a 1 at that position. Keep a reverse movie-index mapping so retrieved columns can become catalog IDs again. A compressed sparse row (CSR) matrix stores the recorded entries rather than allocating every possible cell. section 2.2.2
Listing 2.1 Creating the user-item matrix
user_ids = ratings['userId'].unique()
movie_ids = ratings['movieId'].unique()
user_to_idx = {uid: idx for idx, uid in enumerate(user_ids)} #A
movie_to_idx = {mid: idx for idx, mid in enumerate(movie_ids)} #A
idx_to_movie = {idx: mid for mid, idx in movie_to_idx.items()} #A
rows = [user_to_idx[uid] for uid in ratings['userId']] #B
cols = [movie_to_idx[mid] for mid in ratings['movieId']] #B
data = [1] * len(ratings) #B
user_item_matrix = csr_matrix(
(data, (rows, cols)),
shape=(len(user_ids), len(movie_ids))
) #CThe construction listing shows the ID-to-index mappings, row and column arrays, binary values, and CSR matrix shape. section 2.2.2
Storage matters quickly. A dataset with 162,541 users, 59,047 movies, and 25,000,095 ratings is about 99.74% sparse. Its binary interaction matrix uses about 95 MB in the sparse representation described here, versus roughly 56 GB if stored densely. Sparsity also means recommendations must be inferred from relatively few observed user-item pairs. section 2.2.1 section 2.2.2
The matrix feeds several approaches. A row dot product scores user overlap; column comparisons produce item-to-item similarity for candidate retrieval. Cosine similarity compares movie columns as vectors of users who watched them. At this scale, even a sparse input does not make every derived object small: the full movie-similarity matrix is reported at about 10.4 GB. Matrix factorization takes another route, learning smaller user and item factor matrices whose dot products approximate observed ratings and predict missing ones. section 1.3.2 section 2.2.2 section 3.3.1



