I want to perform clustering. I am reading about this topic but I am totally confused. My dataset has 490 observations and it consists of numerical data (3 columns: Recency, Frequency, Monetary), nominal data (6 columns with more than 3 categories each), ordinal data (1 column with 3 "levels") and boolean data (1 column True/False). What approaches should I try? What data pre processing should I perform for each approach? What else should I investigate in my data before the clustering implementation? I have read about k-prototypes but I don't know how to deal with the ordinal and nominal data in my dataset. Should I do One Hot for the nominal data? Should I map 0,1,2 in the ordinal data(0,1 for the boolean data)? In which columns and in which approaches should I perform scaling? Also, I don't know if it's a problem the fact that the nominal data in the dataset have more than 3 categories each. I also read about Gower Distance with PAM. I know that I don't have a specific question but it would be really helpful if you could clarify some of the above questions and suggest proper approaches.


1 Answer 1


If I were you, I would avoid using the (naive) one-hot encoding because it increases the dimensionality of your data, namely, adds more features/attributes, and introduces collinearity between such features/attribute. Moreover, in general, I would avoid mapping categorical features to $1,2,\ldots,n$, where $n$ is the number of categories, but I should work well on ordinal features; nevertheless, if new data comes and has, say, a new category, then the previous mapping would not account for such a (new) category.

To solve such issues, a better approach is the hash trick or feature hashing that uses a (hash) function defined as:

$$h : \mathcal{C} \to \mathbb{N},$$

where $\mathcal{C}$ is the set of categories and $\mathbb{N}$ are the natural numbers. Being a function, it can have many mathematical properties, and, in this context, "similar" categories could be mapped to "near" numbers using, for example, locally-sensitive hashing.

Finally, once your features/attributes are numerical, you can conduct almost any clustering approach.


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