liveBook · Manning

Collaborative filtering

As explained in AI Recommender Systems

A collaborative-filtering technique that recommends items using the preferences of users with similar interaction patterns.

Collaborative filtering (CF) recommends items from patterns in user behavior rather than item descriptions. If people with similar histories tend to consume the same items, their interactions can help predict what each person might want next. Shared audiences can reveal connections that content-based recommendations miss: two movies need not have similar plots to appeal to the same viewers. CF supports both personalized “recommended for you” lists and item-seeded “more like this” results. section 1.3.2 section 3.2

The input is a user–item interaction matrix: rows represent users, columns represent items, and entries record interactions. Clicks, purchases, watch time, and ratings can supply behavioral signals, though an interaction does not always mean approval. A small example can treat each consumed comic as a 1 and every other comic as a 0; production choices about what counts as an interaction need more care. section 1.3.2 section 1.3

Two simple ways to use the matrix are:

  • User-based CF: find users who consumed the same items, then score items those users consumed but the target user has not. In a small implementation, a dot product measures overlap between user rows; the target user is excluded from their own neighbor list. section 1.3.2
  • Item-based CF: find items consumed by overlapping audiences. A dot product between item columns supplies a simple co-consumption score for item-to-item recommendations. Finding similar users becomes expensive as the user base grows, motivating the item-based alternative. section 1.3.2
Listing 1.6 User-to-item Collaborative filtering
def find_similar_users(matrix: np.array, user_id: int, top_n: int = 3):
    user_sim = np.dot(matrix[user_id], matrix.T)  #A
    user_sim[user_id] = 0  #B
    most_similar_users = np.argsort(user_sim)[::-1][:top_n]  #C
    return most_similar_users.tolist()
 
def get_recommendations(matrix: np.array, user_id: int,
                        sim_users: list, top_n: int = 3):
    not_consumed = (matrix[user_id] == 0).astype(int)  #D
    sim_user_counts = matrix[sim_users].sum(axis=0)  #E
    scores = not_consumed * sim_user_counts  #F
    rec_ids = np.argsort(scores)[::-1][:top_n]
    return [catalog[id] for id in rec_ids]

The user-based implementation shows the complete path from matrix overlap to similar users, unseen-item scores, and recommendations. section 1.3.2

For larger-scale behavioral representations, matrix factorization learns user and item embeddings from interactions. Alternating Least Squares (ALS) decomposes the user–item matrix into factors; their dot product predicts a user’s preference, while item-factor similarity supports related-item retrieval. Factor count, regularization, and iteration count are model-selection choices to test on validation data, not fixed guarantees. section 3.2 section 3.7

From shared viewers to recommendations

In a synthetic comic catalog, 21 users consumed both Asterix and Superman. That co-consumption supplies a behavioral connection even if the comics’ metadata differs. On MovieLens, a behavioral model recommends Star Wars and Indiana Jones films to a user whose ratings include action/adventure and science-fiction films, without using genre labels to make those recommendations. section 1.3.2 section 3.3.7

CF is one component of a recommender pipeline, not the whole serving policy. It can retrieve similar items or score candidates after availability and other business-rule filters; final ordering may also account for diversity and presentation. Compare it with content-based and hybrid approaches rather than judging offline similarity alone. section 1.4.1 section 2.4

Cold start is the central failure mode: a new item has too few interactions to establish reliable similarity, and a new user has no history for personalization. One MovieLens item with a single rating produced near-zero similarity scores despite returning candidates. Content metadata can support new items; a popularity-based fallback can keep results available when behavioral models cannot. Watch for popularity bias too: frequent exposure can generate still more interactions for already-popular items. section 2.2.9 section 1.6 section 2.6

How AI Recommender Systems covers it

How deep it goes
Works through matrix-based user and item similarity, then introduces ALS factors and validation-guided tuning.
Examples
Uses synthetic comic co-consumption, MovieLens ratings, user recommendations, and similar-movie results.
What it assumes
Assumes basic familiarity with users, items, and interactions; teaches the interaction matrix and simple similarity calculations through examples.
What you can do after
Build it from scratch with user–item overlap, then apply ALS-based retrieval while planning cold-start fallbacks.
How it connects
Connects to content-based recommendation, behavioral embeddings, hybrid retrieval, cold start, and the four-stage recommender pipeline.

Also explained in

Compare how 6 books explain collaborative filtering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Recommender Systems. The section links point to the parts of the book it draws on.