User-item matrix

Also known as: interaction matrix · rating matrix

On this page 7

A user-item matrix is a two-dimensional data structure in which rows represent users, columns represent items and each cell holds a recorded interaction, such as a rating, a click or a purchase. In recommender systems, it is the foundational input for collaborative filtering and matrix factorization, and it is also called an interaction matrix or, when it holds explicit scores, a rating matrix.

The central difficulty is that the matrix is overwhelmingly empty. A typical user interacts with a tiny fraction of the catalog, so most cells are unknown, and the task of a recommender is essentially to predict the missing entries or to rank them for each user.

How the user-item matrix is constructed

The user-item matrix is built by aggregating an event log into a grid indexed by user and item identifiers. Each raw event, such as a view, a cart addition or a five-star rating, is mapped to a cell value according to a chosen weighting scheme, and repeated events for the same pair are combined by counting, summing or keeping the latest value.

What a cell means depends on the feedback type. The table below shows the common cell encodings and how each should be interpreted.

Cell encodingExample valueMeaning of an empty cell
Explicit rating1 to 5 starsUnknown preference
Binary implicit1 if interactedUnknown, not necessarily negative
Count or durationPlay count, seconds watchedNo observed engagement
Weighted event scoreView 1, cart 3, purchase 5No observed engagement
Confidence-weightedPreference plus confidence termLow-confidence negative
Common ways to encode matrix cells

Treating empty cells correctly is the most consequential modeling decision. With explicit feedback, empty cells are simply unknown. With implicit feedback, practitioners often treat them as weak negatives with low confidence, the approach used by weighted alternating least squares for implicit data.

Sparsity, scale and storage

Real user-item matrices are extremely sparse, with density commonly below 1 percent and often far below 0.1 percent in large e-commerce or media catalogs. This is the root of the data sparsity problem, which limits how reliably similarities between users or items can be estimated.

Because almost all cells are empty, the matrix is never stored as a dense array in production. The following table compares the storage formats used in practice.

FormatStructureBest suited for
Coordinate list (COO)Triples of user, item and valueBuilding and appending data
Compressed sparse row (CSR)Row pointers with column indicesFast per-user lookups
Compressed sparse column (CSC)Column pointers with row indicesFast per-item lookups
Interaction tableDatabase or columnar file rowsDistributed training pipelines
Storage formats for sparse interaction data

Memory grows with the number of stored interactions, not with users multiplied by items. A matrix of ten million users and one million items with one billion interactions is manageable in sparse form, whereas a dense version would require about ten trillion cells.

How algorithms use the user-item matrix

Nearly every classical recommendation algorithm is a different way of reading the same matrix. Neighborhood methods compare rows or columns directly, while latent factor models approximate the whole matrix as a product of two low-rank factor matrices.

ApproachUses of the matrixMain limitation
User-based collaborative filteringSimilarity between user rowsUnstable when users have few interactions
Item-based collaborative filteringSimilarity between item columnsWeak for newly added items
Matrix factorizationLow-rank approximation of observed cellsNeeds regularization to avoid overfitting
Alternating least squaresAlternately solves user and item factorsRequires careful confidence weighting
Bayesian personalized rankingPairs of observed and unobserved itemsDepends on negative sampling quality
Algorithms and the part of the matrix they exploit

Modern neural approaches, such as two-tower models and sequential recommenders, still learn from the same interaction data, but they add side features and temporal order that a static matrix cannot express. The matrix remains the reference view for evaluation and for simple, strong baselines.

Preparing the matrix for training

Raw interaction matrices need preprocessing before training, because noise, bots and extreme users can dominate the signal. Common preparation steps include the following.

  • k-core filtering: repeatedly remove users and items with fewer than k interactions, which densifies the matrix but hides cold-start behavior.
  • Normalization: subtract each user mean rating to remove individual rating scale bias in explicit data.
  • Weight damping: apply logarithmic scaling to counts so that heavy users do not dominate item similarities.
  • Time-based splitting: hold out the most recent interactions for testing, which prevents leakage from the future into training.

Random splitting of cells is common in academic benchmarks such as MovieLens, but it overstates offline accuracy for production systems, where the model always predicts future behavior from past behavior.

Limitations and common mistakes

The user-item matrix captures who interacted with what, but not why, when or in which context. Its blind spots shape the weaknesses of every model trained on it, and several mistakes recur across teams.

MistakeConsequenceBetter practice
Treating empty cells as dislikesPenalizes items users never sawModel missing data as low-confidence
Ignoring exposureReinforces the recommendation feedback loopLog impressions alongside interactions
Mixing feedback types unweightedClicks drown out purchasesAssign explicit event weights
Over-aggressive filteringInflated metrics, poor cold-start handlingReport results on unfiltered users
Typical mistakes with interaction matrices

The matrix is also not missing at random. Users rate what they chose to consume, and systems show what they already recommend, so observed cells are biased toward popular items. Ignoring this leads to popularity bias and misleading offline evaluation.

Put simply

Imagine a huge spreadsheet where every customer has a row and every product has a column. Whenever a customer buys, watches or rates something, a mark goes into the matching box. That spreadsheet is the user-item matrix.

Most boxes stay empty because nobody tries more than a handful of products. A recommender looks at the filled boxes, finds people with similar marks and guesses which empty boxes would be filled next. Those guesses become the suggestions a person sees.

In practice

An online bookstore with 400,000 customers and 150,000 titles wants to add a recommendation row to its home page. Its data team builds a user-item matrix from one year of purchases and product views, weighting a purchase at 5 and a view at 1, which yields about 12 million stored interactions and a density of roughly 0.02 percent.

The team trains an implicit alternating least squares model on this sparse matrix in CSR format, holding out the final four weeks of activity for evaluation. Recall at the top 10 positions roughly doubles compared with a simple bestseller list on the held-out period.

During review, the team notices that new releases almost never appear. Because new titles have nearly empty columns, the team blends in a content-based score for books younger than 30 days, and new releases reach the recommendation row without reducing overall recall.