1
$\begingroup$

I am working on clustering algorithms. I am working with titanic dataset. It contains 6 categorical features. I used k-means algorithm on this dataset. I am using label encoding for categorical features. But I found that categorical features should use euclidean distance. It should use Hamming distance. So, how to make k-means work finely on mixed features? I don't need other algorithm. I just want to work with k-means only on mixed features dataset.

$\endgroup$
2
  • $\begingroup$ You should use one-hot enconding rather than label encoding $\endgroup$
    – Chopin
    Jun 23, 2020 at 12:16
  • $\begingroup$ How one-hot encoding solves the problem? since using one-hot encoding also results 0s and 1s.when i apply k-means it calculates distance.so it may results in decimal .How to solve that. @Chopin $\endgroup$
    – Sathya
    Jun 24, 2020 at 15:51

4 Answers 4

2
$\begingroup$

Label encoding is not a good idea if the nature of categories are not ordinal (it is actually not my favorite anyways). Use one-hot encoding and see how it works. You may apply a feature extraction on top of it, e.g. PCA, to reduce the noise coming from sparsity. The other idea is to label categories by their fraction in the feature, for example:

[a,b,b,c,a,a] --> [3/6, 2/6, 2/6, 1/6, 3/6, 3/6]
$\endgroup$
0
$\begingroup$

The best way to encode the data will be through any encoding mechanism like label encoder etc. But before handling the categorical variable check the correlation of a categorical variable with the target variable using the feature selection methods like chi square test with selectKbest.

$\endgroup$
0
$\begingroup$

You can quantify correlation, or more precisely association, between categorical variables using something like cross-entropy. There’s an available library dython to compute such association values. Also I am curious why do you want to do clustering ? What is your expected output?

$\endgroup$
0
$\begingroup$

I think the k-prototype algorithm is what you are looking for.

https://link.springer.com/article/10.1023/A:1009769707641

$\endgroup$
0

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.