liveBook · Manning

Similarity matrix

As explained in Graph Neural Networks in Action

A similarity matrix is a matrix whose entries quantify the similarity between pairs of items or representations.

A similarity matrix is a tabular structure whose entries quantify similarity between every pair of items. For node embeddings, cosine similarity compares all nodes and supports nearest-neighbor product recommendations. section 3.1.5

A practical recommendation workflow proceeds as follows:

  • Run the trained graph neural network in evaluation mode to produce node embeddings. section 3.1.5
  • Compute pairwise cosine similarities across the embeddings. section 3.1.5
  • Select a product row, sort similarities in descending order, and map the resulting node indices to product IDs. section 3.1.5

Product bundle generation

For a selected Marceline vinyl figure, the matrix ranks six nearby product embeddings to create a loosely related Toy & Games bundle. section 3.1.5

gcn_similarity_matrix = cosine_similarity(gcn_embeddings.cpu().numpy())

This listing constructs the matrix with scikit-learn from CPU-converted node embeddings. section 3.1.5

How Graph Neural Networks in Action covers it

How deep it goes
Explains matrix construction and nearest-item ranking, but defers the underlying cosine-similarity mathematics.
Examples
Uses Amazon product nodes and a Marceline vinyl figure to demonstrate six-item bundle generation.
What it assumes
Assumes a trained graph neural network can produce node embeddings and that node indices map to product IDs.
What you can do after
Apply it via scikit-learn to rank products nearest to a chosen embedding.
How it connects
Connects node embeddings, graph neural networks, cosine similarity, and product recommendation.

Also explained in

Compare how 3 books explain similarity matrix →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Neural Networks in Action. The section links point to the parts of the book it draws on.