 # Question

We’re introduced to the Manhattan distance in this lesson. What are some applications of this distance function? Is it used often in data science?

One place that the Manhattan distance shows up very often is when working with vectors. Suppose, for example, that we have two vectors: `v1` with coordinates `(x1, y1)` and `v2` with coordinates `(x2, y2)`. The difference between `v1` and `v2` is defined by how many units we must move horizontally and vertically to get from one vector to the next. Since the amount that we move in either direction is greater than or equal to zero, we need our difference to be non-negative. We can guarantee this by simply taking the absolute value. Therefore, our differences are `|x1 - x2|` units horizontally and `|y1 - y2|` units vertically, for a total of `|x1 - x2| + |y1 - y2|` units; this is exactly Manhattan distance between the two vectors.

Note: You will also come across the Manhattan distance under other names. For example, taxicab metric and `L1` norm are common alternatives.

3 Likes

Appreciate the answer but i don’t think it is answering the question but only talking about how the Manhattan distance works.

1 Like

All of the distance functions used in these exercises are utilised when calculating dissimilarity in heirarchical clustering.

As far as I can make out, any appropriate metric can be used for the observations in question, which are then converted into a matrix of distances using one of the aforementioned methods. A series of loops progressively place the closest pairs together, and then those pairs into clusters and so on until a final cluster is reached that includes all observations, completing the tree.

Distance is often used for classification algorithms (unsupervised learning).
Imagine you have a bounch of points in a graph (they might be price vs. seze of a house, salary vs degree of studies, etc). You want to classify these points in two groups (or tree, four, etc). One way is to pick a representative point and calculate the distance between this point and every other point. Those points with a distance less than, say 10 units, will belong to the group of this representative point.