Computing distances

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 ...

Get Training Systems Using Python Statistical Modeling now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.