I have a dataset with mixed datatypes:

id    amount    creator    accounts
1     100       jane       cash
1     100       jane       accounts receivable
2     200       john       tax account

Each id can have only one creator. Each id can have one or more accounts. For the accounts data, I am one hot encoding the accounts and then joining them into a bitmap:

id    amount    creator    accounts
1     100       jane       110
2     200       john       001

My plan was to apply k-prototypes to the resulting dataset. K-prototypes uses k-modes and the Hamming (# of replacements) distance to calculate similarity between categorical features and the modes. I think this works well for the bitmaps with multiple 1s. However, Hamming distance does not make sense for creator, because my assumption is that people are not more similar just because they have similar names. Therefore, I need to one hot encode the creator feature as well.

After one hot encoding, does it make sense to combine the creator features into a bitmap like the accounts? Each id can only have creator, so the bitmaps would only have replacement counts of 0 or 1.

Alternatively, am I overthinking this? Should k-modes actually be applied directly to single-value categorical variables?


K-modes should directly on the categorical data, not on a one-hot encoding. John != Jane != Mary. Otherwise, the mode will usually be 0, and your prototypes are all 0.

But if you do not expect the creator attribute to be important, then do not use it.

| cite | improve this answer | |
  • $\begingroup$ So as long as it's a single-value categorical feature, just apply k-modes directly? Let's say the names are John, Joan, and Mary. Wouldn't John and Joan be deemed more similar (1 substitution) than John and Mary (4 substitutions)? $\endgroup$ – OverflowingTheGlass May 2 '18 at 13:21
  • $\begingroup$ No. That would require transforming the labels to a byte array of a fixed length, and for string editing you'd use Levenshtein instead of Hamming and not kmodes. John != Jane. 1 column different: the name column. Only John = John is no difference. $\endgroup$ – Has QUIT--Anony-Mousse May 2 '18 at 18:19
  • $\begingroup$ Thank you very much - that makes sense. The bitmap makes sense for the accounts feature though, right? Since there are multiple possible values, the bitmap seems like it simply creates one string that is a representation of all the strings. $\endgroup$ – OverflowingTheGlass May 2 '18 at 20:07
  • $\begingroup$ This: rosalind.info/glossary/hamming-distance seems to oppose your description, but I could be missing something $\endgroup$ – OverflowingTheGlass May 2 '18 at 20:17
  • $\begingroup$ To add more detail - it seems like Hamming Distance requires strings of the same length, and the similarity measure is based on substitutions of symbols (i.e. letters). $\endgroup$ – OverflowingTheGlass May 2 '18 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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