liveBook · Manning

Cosine similarity

As explained in Graph Algorithms for Data Science

Cosine similarity is a measure of the angular resemblance between two vectors, computed from the cosine of the angle between them.

Cosine similarity measures how similarly two vectors point by taking the cosine of the angle between them. It compares direction rather than simply the numerical size of feature values, making it useful for comparing node representations in a similarity network. section 8.0

Interpret the score and its role in nearest-neighbor analysis:

  • A score of 1 means identical direction; the measure ranges from -1 to 1. section 8.0
  • Compare pairs of user vectors and create relationships when their similarity passes a chosen threshold. section 8.0
  • Use cosine similarity without normalizing features first, but treat normalization differently when using metrics such as Euclidean distance. section 8.2.1
  • Recognize that inferred similarity links need not match links in the original network. section 8.0

User segmentation with a nearest-neighbor graph

Represent users with features such as tweet count, retweet ratio, time to retweet, degree measures, graphlets, and centralities. Neo4j Graph Data Science can use pairwise cosine similarity through gds.knn to create SIMILAR relationships, storing the score while topK and similarityCutoff control network density. A denser graph produces larger communities; a sparser graph produces more granular segments. section 8.2 section 8.2.2

Figure 8.2 Cosine similarity is measured as the cosine of the angle between two vectors.
08-02

View the angle-based geometry used to interpret cosine similarity. section 8.0

How Graph Algorithms for Data Science covers it

How deep it goes
Defines angular similarity, score interpretation, normalization implications, and thresholded graph construction without presenting the underlying formula.
Examples
Demonstrates user vectors built from activity, degree, graphlet, closeness, and betweenness features.
What it assumes
Assumes numerical vector representations and feature extraction, while defining cosine similarity and its basic interpretation.
What you can do after
Apply it via Neo4j GDS gds.knn to construct a scored similarity graph for downstream community detection.
How it connects
Connects vector representations, node features, nearest-neighbor graphs, feature normalization, and community detection.

Also explained in

Compare how 14 books explain cosine similarity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Algorithms for Data Science. The section links point to the parts of the book it draws on.