What is the best encoder for categorical data in unsupervised learning?

I am using unsupervised learning on mixed data (such as K-means).

Before running my unsupervised algorithm, I am using dimension reduction of my data using FAMD (PCA for mixed data) which allows me to obtain coordinates and reduce the dimension of my dataset.

The FAMD required One-hot encoding (aka Dummies Variable) and it's based on SVD. The SVD could be very time-consuming if the number of dimensions is high, and this is my case when I have categorical variables with a large number of modalities.

So I am looking for an encoder suitable for categorical data in the context of unsupervised learning.

I've found some pretty good encoders for supervised learning (target encoding as an example) but it's not adapted for unsupervised learning.

related post: Unsupervised encoding of categorical features


1 Answer 1


Different unsupervised machine learning algorithms have different assumptions. K-means clustering requires computing euclidean distance thus all encodings have to be consistent with euclidean distance computation.

Encoding categorical variables into a continuous embedding space (e.g., word2vec) would be consistent with euclidean distance computation.

One hot encoding is not consistent with euclidean distance computation.


Your Answer

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

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