# Is there a distance algorithm similar to Jaccard distance that handles scalar data?

we have the characteristics and (scalar) values of those characteristics for three (or more) people:

Person A: {height: 1, weight: 2, type: 1}

Person B: {height: 1, weight: 2, type: 5}

Person C: {weight: 2, type: 1}


I'm trying find a distance measure that helps decide if Person A and C are more similar to each other or if Person A and B are.

If we had categorical data, I would use the Jaccard distance, but now I am trying to include the scalar values in the calculation.

The key concept is that there are some pairings where the characteristic set is incomplete and I would like to know if there is any distance scoring algorithm that handles that elegantly.

PS I'm not really sure how to ask this question and quite new at this, so please feel free to ask me to edit / rephrase rather than closing the question if it's not up to community standards.

• I would be careful using distance measures when the dimensions have vastly different distributions. Let's say height and weight are nearly Gaussian, and type is Poisson. – Aksakal Apr 27 '15 at 18:54
• When you have different types of variables (continuous, ordinal, categorical), the default distance is Gower's distance, see this pdf. – gung - Reinstate Monica Apr 27 '15 at 19:22

## 1 Answer

I would use Mahalonobis distance. When the variable is missing, simply skip it when constructing the covariance matrix and the distance itself.

• For people reading this in the future, here is a link to its implementation in Python. docs.scipy.org/doc/scipy-0.14.0/reference/generated/… – Phil B Apr 27 '15 at 18:51
• Check that it handles missing data the way you expect. – Aksakal Apr 27 '15 at 18:52
• I'll run some tests on it later, thanks a lot for the quick answer! – Phil B Apr 27 '15 at 18:54