liveBook · Manning

Euclidean distance

As explained in Natural Language Processing in Action, Second Edition

Euclidean distance is the straight-line distance between two points or vectors computed from the square root of the sum of squared coordinate differences.

Euclidean distance measures the straight-line separation between two points or vectors. In an orthogonal, rectilinear vector space, subtract corresponding coordinates and take the square root of their squared differences: the Pythagorean theorem provides the calculation. section 3.2.3 section 3.3

Comparing two term-frequency vectors

Represent two documents as Vec1 = (1, 0) and Vec2 = (2, 1), where coordinates can represent word frequencies. Subtract one vector from the other, then calculate the length of the resulting difference vector. That length is their Euclidean distance. section 3.3

Euclidean distance is also called Cartesian distance, the L2 distance, or the 2-norm. It works naturally for a small number of dimensions, but high-dimensional NLP vectors often use cosine distance instead because Euclidean magnitudes can become unwieldy. section 3.3 section 4.6

Coordinate geometry matters: latitude and longitude lie on an approximately spherical surface, so ordinary Euclidean distance is unsuitable for long geographic routes, although it can approximate nearby locations. section 3.2.3

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Defines the formula geometrically, works through vector subtraction, and stops short of detailed high-dimensional implementation.
Examples
Uses 2D term-frequency vectors, vector diagrams, and geographic latitude–longitude coordinates.
What it assumes
Assumes basic vectors and the Pythagorean theorem while explaining distance through coordinate subtraction.
What you can do after
Apply it via vector subtraction and NumPy for low-dimensional comparisons, then evaluate cosine distance for high-dimensional vectors.
How it connects
Connects vectors, vector spaces, L2 norm, TF-IDF, cosine distance, cosine similarity, and feature vectors.

Also explained in

Compare how 8 books explain Euclidean distance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.