Prepare interaction data
Collect user–item interactions and pivot them to a user-by-item matrix, filling missing values appropriately.
Recommend friends by similarity. Suggest items from neighbours.
Friend recommendation often combines behaviour, social graph features and profile metadata to suggest likely connections. Simple collaborative approaches compute user–user similarity from shared interactions; production systems then add diversity, safety rules and privacy protections. Common failure modes include sparse interaction data, popularity bias and echo chambers.
Learning concept · Not a validated service
Friend recommendation often combines behaviour, social graph features and profile metadata to suggest likely connections. Simple collaborative approaches compute user–user similarity from shared interactions; production systems then add diversity, safety rules and privacy protections. Common failure modes include sparse interaction data, popularity bias and echo chambers.
A proposed application for a social app: surface candidate friends who share interaction patterns and mutual interests while letting users control suggestions. Any deployment should preserve user privacy and allow users to opt out; this starter does not implement privacy controls.
Collect user–item interactions and pivot them to a user-by-item matrix, filling missing values appropriately.
Use cosine similarity on the user vectors to score pairwise similarity and identify nearest neighbours.
For a target user, select neighbours and surface candidate items or candidate users based on neighbour behaviour.
Measure offline ranking metrics, inspect cold-start users and check for popularity or echo-chamber effects.
The supplied starter builds a small user–item rating table from six users and five items, pivots it to a dense matrix, computes cosine similarity between users, finds the most similar user to a target, and prints the neighbour plus that neighbour's highest-rated unseen items. It does not construct or evaluate a friend-ranking list from social graph features, nor does it use a larger or realistic dataset.
matrix = ratings.pivot_table(index="user", columns="item", values="rating").fillna(0)
user_similarity = pd.DataFrame(
cosine_similarity(matrix),
index=matrix.index,
columns=matrix.index,
)The starter uses a tiny synthetic ratings table (four users in the pivot) and then recommends items from the single most similar user. It does not compute or validate friend candidates, lacks train/test splits and metrics, and cannot support production claims from its toy data.
A proposed extension: use interaction logs plus profile and mutual-friend features to rank candidate friends. Train a supervised model on historical link-formation events, add filters for diversity and safety, and log signals for offline/online evaluation.
This is a potential application pathway, not a delivered product. The supplied starter does not implement this service or validate it with real users.
Networkers Home runs this topic inside its AI Engineer Course, with placement support and hands-on labs.