Skip to content

Model Evaluation

Euclidean Distance

In shortEuclidean distance is the straight-line distance between two points in any number of dimensions, used to compare numeric data and vectors.

Updated 25 Oct 2026· 2 min read

Euclidean distance is the straight-line distance between two points, the “as the crow flies” distance you would measure with a ruler, extended to any number of dimensions. In machine learning it measures how far apart two data points are when each is described by numbers, such as customers described by spend and visit frequency, or texts described by embedding vectors. The smaller the distance, the more similar the two points.

How it works

For two points, subtract each coordinate from the other, square the differences, add them up and take the square root. In two dimensions, the points (1, 2) and (4, 6) are the square root of 3² + 4², which is 5, apart. The same formula works for embeddings with hundreds of dimensions; there are simply more differences to add up.

MLforSEO’s clustering lesson lists it alongside cosine similarity and Manhattan distance (the sum of absolute differences, like walking city blocks) as the metrics clustering algorithms use on numeric data. K-means uses it by default to assign each point to its nearest centroid, and Ward linkage in hierarchical clustering is built on it.

The two main metrics look at different things. Euclidean distance is sensitive to magnitude, the length of the vectors, while cosine similarity only compares their direction. Google’s clustering course notes that once vectors are normalised to the same length, Euclidean distance, cosine and dot product become proportional and effectively measure the same thing.

How it’s used in SEO and marketing

  • Customer segmentation: clustering customers on scaled recency, frequency and monetary (RFM) features with K-means or Ward hierarchical clustering, as in our customer segmentation notebook.
  • Clustering reduced embeddings: our BERTopic tutorial reduces embeddings with UMAP using a cosine metric, then runs HDBSCAN with Euclidean distance on the lower-dimensional output.
  • Nearest-neighbour search: vector databases let you choose Euclidean (often called L2), cosine or dot product as the metric for vector search.
  • Outlier checks: pages, accounts or customers that sit far from every cluster centre.

When to prefer cosine for text

For raw text vectors, such as TF-IDF scores or word counts, use cosine. A long page and a short page on the same topic point in a similar direction, but sit far apart in Euclidean terms because the long page has bigger counts. With sentence embeddings, cosine is the usual default in tools such as Sentence Transformers, and Euclidean gives the same ranking of neighbours if the vectors are normalised. Our clustering guide makes the same point: text similarity is normally measured with cosine in embedding space rather than plain Euclidean distance.

Limitations and things to watch

  • Scale dominates. A revenue column in thousands swamps a visits column in single digits, so standardise features before measuring distance.
  • In very high dimensions, distances between points become more alike, which weakens the contrast between near and far neighbours. Dimensionality reduction helps.
  • It works only on numbers. Categories must be encoded first, and strings need a different measure such as edit distance.
  • A distance is not a similarity score. Lower is closer, so convert it before mixing it with other scores.

Learn it on MLforSEO

Where Euclidean Distance shows up on MLforSEO

Sources and further reading

Other terms from Model Evaluation

See all 19 Model Evaluation terms →