0
$\begingroup$

I have a dataset with the following variables (among ohter variables) that represents custome card transactions and I'm trying to cluster the clusters using k-means.

GENDER_M: can be 0, 1 or NA
GENDER_F: can be 0, 1 or NA

I'm trying K-means using R packages NbClust and cluster

Now, on this other question I wrote that hot encoding these variables didn't work out very well. I tried:

GENDER_M0: 1 for all the records that contain 0 in column GENDER_M - 0 otherwise
GENDER_M1: 1 for all the records that contain 1 in column GENDER_M - 0 otherwise
GENDER_MNA: idem
GENDER_F0: idem
GENDER_F1: idem
GENDER_FNA: idem

So, in total, I have 5 possible combinations:

NA/NA
0/0
0/1
1/0
1/1

1 means that there's a presence of the respective gender in the buying patters of the customer. For example, if a customer buys razors repeatedly, he will get a 1 in column GENDER_M.

Can anyone advise on a good method to deal with categorical variables in a clustering problem?

Thanks

$\endgroup$
3
  • $\begingroup$ I think you will find the information you need in the linked thread. Please read it. If it isn't what you want / you still have a question afterwards, come back here & edit your question to state what you learned & what you still need to know. Then we can provide the information you need without just duplicating material elsewhere that already didn't help you. $\endgroup$ Commented May 1, 2019 at 18:09
  • $\begingroup$ The generic K-Means is not directly applicable for categorical data because the distance metrics like Euclidean Distance does not make sense for categorical data. You could try looking into K-Modes Clustering which was introduced to deal with categorical variables while clustering. You might also want to look into the Gower Distance that can help deal with a mix of categorical and numerical variables. You will find implementation for both K-Modes and Gower Distance in R. $\endgroup$
    – frank
    Commented May 1, 2019 at 18:15
  • $\begingroup$ Sure, I'll have a look at k-modes and figure out the best way to solve the problem. Thanks for your help $\endgroup$ Commented May 1, 2019 at 18:17

0

Browse other questions tagged or ask your own question.