Choosing a notion of distance is important for clustering. Also, once we accept that there are different ideas of what it means to be distant, we can answer different problems more effectively. To drive home the idea of different distance metrics, I want to demonstrate how to compute different distances. The first thing I will show is how to compute Euclidean distance, which corresponds to how we normally think about distance.
We will use a function that computes the Euclidean distance for two NumPy vectors, presumably of the same length, using the following lines of code:
Now, let's create two vectors: vec1 and vec2; imagine ...