Euclidean Distance is the ‘ordinary’ straight line distance between two points in Euclidean Space.

It can be seen in action as the frustrating difference in distance between how far away something is (the straight line distance) and how far you have to go to get there (the rather disappointingly named distance travelled).

Conveniently for machine learning Euclidean Space generalises to high dimensional spaces (three dimensions would be a touch restrictive for most classification problems). However, as with most distance metrics its usefulness does tend to break down under the Curse of Dimensionality

Since we can’t get a ruler out and measure the Euclidean distances in n-dimensional space (although please do let me know if you manage to locate an n-dimensional ruler) we need to use algebra to calculate it.

This bit of algebra specifically:

## Pythagoras

This complex and scary looking bit of maths breaks down to Pythagoras’ Theorem:

This works because each of these vectors is actually a right angle triangle^{1}, and the dot product of a vector gives us the extent to which the vectors go in the same direction. So we’re just solving the green triangle.

## Vectors

Let’s go back and look at why that works. (This bit is going to involve a bit more mathematical notation than the rest did.)

We’ve got some arbitrary vectors \(a\) and \(b\) of length \(n\) and we want to know how far apart they are:

We’re going to use this section of the distance function to work that out (or more accurately to prove that both ways of writing our distance function are equivalent):

Vectors are a single row matrix so “dotting” them with themselves is done in the same way as you do with a matrix^{2}:

Terrifying, right? Just take the first item from each and multiply them together:

We can simplify that again as something multiplied by itself is squared:

Which in turn can be reduced to the sum (add all the items together) of the squares of all the values from 0 to wherever (\(i\)):

Which is where we started. Woohoo we proved Euclidean distance works.