# Euclidean distance score and similarity

I'm just working with the book Collective Intelligence (by Toby Segaran) and came across the Euclidean distance score. In the book the author shows how to calculate the similarity between two recommendation arrays (i.e. $\textrm{person} \times \textrm{movie} \mapsto \textrm{score})$ .

He calculates the Euclidean distance for two persons $p_1$ and $p_2$ by $$d(p_1, p_2) = \sqrt{\sum_{i~\in~\textrm{item}} (s_{p_1} - s_{p_2})^2}$$

This makes completely sense to me. What I don't really understand is why he calculates at the end the following to get a "distance based similarity":

$$\frac{1}{1 + d(p_1, p_2)}$$

So, I somehow get that this must be the conversion from a distance to a similarity (right?). But why does the formular looks like this? Can someone explain that?

• There can be many ways to convert dissimilarities and similarities into each other - the specific formula depends on what make sense to you and for the future analysis. In that textbook the author preferred the formula you show for some reason; someone else in a different situation might choose another formula. The most geometrically correct way to convert euclidean distance into a similarity would follow from cosine theorem under data-are-centered condition and is described here in par. 1. – ttnphns Mar 23 '13 at 12:51
• Ok! But If I understand right you don't really convert the euclidean distance into a similarity, but you just use a different function that returns you values within 0 and 1 (because of the cosine), right? I mean it seems different to me than calculating all the distances and then converting them to a similarity by e.g. interpolating between the smallest and the largest distance. Right? – navige Mar 23 '13 at 13:26
• If you have a square symmetric matrix of squared euclidean distances and you perform "double centering" operation on it then you get the matrix of the scalar products which would be observed when you put the origin od the euclidean space in the centre of your configuration of objects. These scalar products are angle-type similarities. They are much like covariances. They are not bound within range 0-1, they can be negative, positive, and diagonal elements are not necessarily 1. Still, they are similarities. – ttnphns Mar 23 '13 at 13:55

The inverse is to change from distance to similarity.

The 1 in the denominator is to make it so that the maximum value is 1 (if the distance is 0).

The square root - I am not sure. If distance is usually larger than 1, the root will make large distances less important; if distance is less than 1, it will make large distances more important.

• Sorry! Square root was wrong. The author actually put it in the second formula, but left it out in the first. So it shouldn't be there – navige Mar 23 '13 at 12:20
• Yes, but your hint with setting the maximum value to 1 makes sense! Thanks! – navige Mar 23 '13 at 12:21

To measure the distance and similarity (in the semantic sense) the first thing to check is if you are moving in a Euclidean space or not. An empirical way to verify this is to estimate the distance of a pair of values ​​for which you know the meaning.

As you mentioned you know the calculation of Euclidence distance so I am explaining second formula.

Euclidean formula calculates the distance, which will be smaller for people or items who are more similar. Like if they are same then distance is 0 and totally different then higher than 0.

However we need a function that gives a higher value of they are similar. This can be done by adding 1 to the function(so you don't get a division-by-zero error) and inverting it. Like if distence 0 and similarity score 1/1=1

• I don't understand this answer. – Michael R. Chernick Aug 6 '18 at 5:05
• ok let say the Euclidean distance between item 1 and item 2 is 4 and between item 1 and item 3 is 0 (means they are 100% similar). These are the distance of items in a virtual space. smaller the distance value means they are near to each other means more likely to similar. Now we want numerical value such that it gives a higher number if they are much similar. So we can inverse distance value. But what if we have distance is 0 that why we add 1 in the denominator. so similarity score for item 1 and 2 is 1/(1+4) = 0.2 and for item1 and item 3 is 1/(1+0) = 0 – user10009133 Aug 8 '18 at 10:33
• Maybe you are talking about some sort of distance measure but Euclidean distance follows a specific formula regarding a vector space. – Michael R. Chernick Aug 8 '18 at 18:36
• I AM EXPLAINING why WE calculates at the end the following to get a "distance based similarity": $1/1+d(p1,p2)$ – user10009133 Aug 11 '18 at 4:46