# Minkowski distance with Missing Values

Im currently doing a subject for data science, and have the following point that im trying to understand.

We are looking to calculate distance in data sets where values may not be present. Now i know that R does this by default, but we are learning the "how" behind the what.

Literature we are give states. "The idea is to normalise the inner sum by the number of valid (non-missing) terms, so distances computed from different amounts of terms are commensurable. Otherwise, distances computed with fewer missing values tend to be artificially larger."

Given the following data set. We have the following sample formulas for Euclidean and Manhattan

Euclidean distance: d(x1, x2) = √(4/3) *( (2 – 7)2 + (1 – (-4))2 + (0 – 8)2 ) = √(4/3)*114 = 12.328

Manhattan: d(x3, x4) = (4/2) * ( |3 – 10| + |2 – 5| ) = (4/2)*10 = 20

Assuming the normalization section fro euclidean is number of non missing terms of each row divided?

How do you derive the normalization section on the Manhattan formula?

• Welcome to the site! You have two different issues here. First is the definition of Euclidean and Manhattan distances. Second is dealing with missing values. – mapto Sep 11 '18 at 8:11

The way you type formulas is a bit confusing, but here's a go at interpeting it.

Euclidean distance is defined by: Manhattan distance is defined by: Handling missing terms is an independent issue. The way it is handled in the example is by taking the average of the present features (dividing by their number) and multiplying by the total number of features as a way to bring the data to a scale comparable to datapoints without missing features.

Now let's have a closer look at the example. The total number of features is 4. To calculate a distance between datapoints you can only use features that are present in both:

• The first (Euclidean) formula finds 3 features present in both x1 and x2. Thus your coefficient is 4/3.
• The second (Manhattan) formula finds two features present in both x3 and x4. Thus the coefficient is 4/2.