0
$\begingroup$

Let assume I have a dataset like this dataset where there are several textual attributes even continuos attributes like age. I have always encountered cases where k-nn is applied on just two attributes and all of those ones numerical. How can I properly apply k-nn in a dataset like that?

$\endgroup$

1 Answer 1

2
$\begingroup$

You can code each of the categorical variables (such as race, marital status, etc.; the ones you are referring to as textual variables) as a set of boolean (1/0) dummy variables. So for instance you'd have one column for each race in the data set with a value of 1 if the subject was of that race and 0 otherwise, i.e for this data set you'd add 5 race columns, White, Asian-Pac-Islander, etc. So you'd add a You'd need to do that for each of the categorical variables.

See discussion here for more information on how to apply k-nn to problems like this.

$\endgroup$
2
  • $\begingroup$ After doing that which could be the best next move from your perspective in terms of calculating distance? $\endgroup$
    – Mazzy
    Commented Jul 27, 2014 at 0:01
  • $\begingroup$ I don't think I can give you better advice than was given in the thread I pointed you too. I took a look at the thread and the most specific advice I saw for the categorical variables referred to Hamming distance for the binary variables. For the real-valued variables usually people use something Euclidean distance. So you'd need to do following: $\endgroup$
    – JeffM
    Commented Jul 27, 2014 at 16:46

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.