0
$\begingroup$

Practicing KNN and I just had a query about pre-processing, as I understand KNN doesn't work with categorical features.

I've read into one-hot-encoding (dummy variables) which I suppose if I applied to the below dataset, would essentially double the amount of columns I have.

However, is this required. Would it work to simply replace y with 0, and n with 1 across the whole dataset?

target     Q1     Q2     Q3  
Wealthy     y      y      y         
Wealthy     n      y      y          
Poor        y      y      y   
Poor        n      y      n          
Poor        y      y      y         
$\endgroup$

1 Answer 1

1
$\begingroup$

In order to apply machine learning, all data must be represented as numbers. The n/y should be replaced with 0/1.

k-nearest neighbors algorithm (k-NN) requires a distance metric. One option is to use Hamming distance with booleans values (0/1).

$\endgroup$
1
  • $\begingroup$ Thanks. So would just replacing them with 0/1 be known as binary encoding, and is there a reason I'd use this over one-hot encoding? $\endgroup$ Dec 7, 2021 at 23:07

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.