2
$\begingroup$

Starting Point: I want to calculate the distances between nominal data. Furthermore, I want to see what difference it makes to only use important features (given some feature selection method). So I calculated the Hamming Distance with important nominal Features. I now want to discover what happens if I create dummy variables (one-hot encoding) and calculate the distance between only important dummy variables.

I tried out the dice distance as it yields the same distance for dummies as the hamming distance for nominal data when using all features.

The Dice distance is calculated by: $D(x,y) =1- \frac{2a}{2a+b+c}$,

where a: number of times x and y equal 1

b: number of times x = 1 and y = 0

c: number of times x = 0 and y = 1

Problem: When taking only the important dummy variables, it can happen that $a = b = c = 0$!. So the Dice Distance returns Nan.

So what is the distance between two observations whose important dummy variables are all equal to zero? Is it simply 1, because there is no match? Is it 0 because two observations are identical and it should be that $D(x,y) = 0 $ if $ x = y$?

Or are there binary distance measures that are more suitable for this task? I personally liked the dice distance for its comparability with the hamming distance.

$\endgroup$
0
$\begingroup$

When dealing with fractions that contain a denominator that may equal to $0$, it is always a good idea to add a very small value to the denominator to avoid dividing by $0$.

For example, in the case of the dice distance, it becomes:

$$ D(x,y) =1- \frac{2a}{2a+b+c + 10^{-9}} $$

This means that when $a=b=c=0$, then the dice distance will equal $1$. $10^{-9}$ is an arbitrary value here. You can choose smaller values if you want.

$\endgroup$
2
  • $\begingroup$ Nevertheless the question remains if that is suitable for the task. Two identical points would know have the maximum distance with does not seem right... $\endgroup$ – Malte Mar 7 at 10:54
  • $\begingroup$ Your question has several sub-questions. I only answered the first one. What was wrong with using the Hamming distance? Cosine similarity may also be used here $\endgroup$ – mhdadk Mar 7 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.