1
$\begingroup$

I am planning to use data for a clustering problem that contains a column with a binary value BUY/SELL.

Should I be converting this attribute and assign it binary values (BUY=1, SELL=0), and keep it on the same column, thus reducing the number dimensions

OR

Hot encode the attribute (adding two columns BUY and SELL and putting 1 on the appropriate column)?

How do these two methods of nominal to numeric conversion affect the final model for popular clustering algorithms (K means, Hierarchical, etc...)

$\endgroup$

2 Answers 2

1
$\begingroup$

Not much of difference in your case. The difference is in just 1 dimension which does not affect much. The only point I can add is that if the number of BUY and SELL values are not the same, you can replace them with their frequencies i.e. if 40% BUY and 60% SELL, then replace BUY with 0.4 and SELL with 0.6

$\endgroup$
1
  • $\begingroup$ Exactly this. Also don't forget to scale it to your data (if you have are working on a TV shop, and have a variable 'price', varrying between 200 and 800, having a binary variable varrying between 0 and 1 will not have any impact on your clustering. Think about normalizing.) $\endgroup$
    – Adept
    Jul 29, 2021 at 12:03
0
$\begingroup$

If one value has more priority than the other, then you can go with binary encoding. e.x) If the values are based on education level, you can assign 0 to school-level education and 1 to college-level education.

If the values do not have any arithmetical dependency, then you need to go for one-hot encoding.

In your case, hot encoding is better.

Edit: If we have only two values, either binary encoding or hot encoding will work. This edit is based on the comment from @beamsadept.

$\endgroup$
2
  • $\begingroup$ This would work with 3 or + values, it's not a problem if they're only 2. The problem is, when you have 1, 2 and 3, that distance between 1 and 2 is not the same that distance between 1 and 3, so it defines an order. Here, since you have 2 possibilities, the distance will always be the same if you don't have the same value $\endgroup$
    – Adept
    Jul 29, 2021 at 11:59
  • 1
    $\begingroup$ @BeamsAdept Yes, after giving some thought, I had to agree with you. If we have only two values, binary coding will work fine. $\endgroup$
    – Venkat
    Jul 29, 2021 at 12:27

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.