1
$\begingroup$

I m looking how to preserve Euclidean distance with categorical attribute.

Ad example, if I have a dataset with attribute of people, Age, weight etc..and i find a attribute "sex" where contain "female" ad "male" for gender, how can i do for analysis?

I seen that i can trasform in 0 and 1, but for me dont have more sense. Why i can't choose 10 and 20 like number for male and female? I Wish that this value in my analysis take a sense.

Sameone have to suggest or explain a great tecnique?

$\endgroup$
5
  • $\begingroup$ One hot encode and find similarity. It will be bound for categorical parts. If you trying to mix categorical/continuous to find some distance, there are already answers here $\endgroup$ Commented Mar 26, 2019 at 6:19
  • $\begingroup$ You speak about Cosine similarity? Can apply PCA after dummy trasformation? For me don't have more sense @KiriteeGak $\endgroup$
    – theantomc
    Commented Mar 26, 2019 at 9:02
  • $\begingroup$ Yes, cosine similarity will do. I have no clue why you are thinking of pca, but no it is not useful. $\endgroup$ Commented Mar 26, 2019 at 9:06
  • $\begingroup$ No Need ti apply PCA after for cluster? Exist a way to cosine similarity for cluster ? $\endgroup$
    – theantomc
    Commented Mar 26, 2019 at 11:17
  • $\begingroup$ If you want to use a distance metric it is usually usefull to scale or standardize your values. So one big value does not hide smaller values. Eg Male/Female 1/0 is not too small compared to Age which can be from 0 to 100. $\endgroup$
    – Malo
    Commented Jan 2, 2022 at 15:07

1 Answer 1

-1
$\begingroup$

If i understand your question correct, you are misusing the word categorical. Categorical is always a 0 or 1 in their respective indices.

for example:

Data - [M, F, M, M]

Categorical Data: [[1, 0], [0, 1], [1, 0], [1, 0]]

If three types of classes are there, then it would be a 3 arrayed input for each datapoint.

If you feel that having the numbers 10 and 20 for Male and Female is meaningful to you, then you can go ahead and use it. There's nothing wrong in that. But when you want to finally train on the Data, say LSTM, it prefers taking in the categorical data.

But if you are talking about the input attributes, then you need not worry about the 0-1 problem, Just use as they are.

Vote up, if you find this helpful ;)

$\endgroup$
5
  • $\begingroup$ But if i have 2 attribute, ad example M and F and another features that represent subscribe or not in a website ad example (that can i have just value like yes and no) I have M= 1, F=0 and Yes=1 , No=0 ...So male guys that are subscribe will be cluster togheter...this make sense? $\endgroup$
    – theantomc
    Commented Mar 26, 2019 at 9:01
  • $\begingroup$ Yes. then in that case, the value defined will just make sure that the intra cluster distance is more. But even if the values are binary, the clusters will be same. $\endgroup$ Commented Mar 26, 2019 at 22:01
  • $\begingroup$ i wish avoid that people will be cluster as the same , for value that i had put in my dataset $\endgroup$
    – theantomc
    Commented Mar 27, 2019 at 7:49
  • $\begingroup$ It is 0 or 1 if you have OneHotEncoded the categorical feature. Before encoding a categorcial value can be : red, bue, white, yellow if you consider a color.... $\endgroup$
    – Malo
    Commented Jan 2, 2022 at 15:09
  • $\begingroup$ Using 10 and 20 may be not good as you need to scale or standardize your values before calculating a distance metric. So evey value is betwwen 0 and 1 or -1 and 1 $\endgroup$
    – Malo
    Commented Jan 2, 2022 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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