2
$\begingroup$

I am trying to do clustering with a bunch (24) of categorical features. I have done some research and found a lot of people recommending something such as K-Modes. I tried running K-Modes on my data and the best run had a cost of 27069.0, which seems pretty high.

Some of my features have only a few values, such as P, O, C, T, so I thought I could encode them. But others have many different values. Any tips on a clustering algorithm or some other approach? I would like to use Python.

EDIT: What about using Gower distance on the data and then using K-Means on that?

$\endgroup$
1

1 Answer 1

1
$\begingroup$

You can one-hot encode all your features, first. Then, you will face with a sparse feature space. To resolve this issue, you can use an auto-encoder to encode all these values to a low-dimensional and more dense space. Then run one of your clustering methods such as k-means.

$\endgroup$
6
  • $\begingroup$ Thanks! Any recommendations on how to do the auto-encoding part? $\endgroup$
    – formicaman
    Commented Mar 16, 2020 at 18:48
  • $\begingroup$ What if I use OneHotEncoder and then my resulting matrix is not sparse? $\endgroup$
    – formicaman
    Commented Mar 18, 2020 at 17:09
  • $\begingroup$ @formicaman as you described the data, after the encoding, it will be sparse. For the auto encoding, use an auto encoder : ) $\endgroup$
    – OmG
    Commented Mar 18, 2020 at 17:22
  • $\begingroup$ I used 'scipy.sparse.issparse(X_encoded)' and it returned 'False'. But I am looking at blog.keras.io/building-autoencoders-in-keras.html for auto-encoding. $\endgroup$
    – formicaman
    Commented Mar 18, 2020 at 17:47
  • $\begingroup$ @formicaman oops! You are in the wrong way! scipy.sparse.issparse is for the type of the variable, not about the concept of matrix sparsity! $\endgroup$
    – OmG
    Commented Mar 18, 2020 at 18:08

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.