Skip to main content
2 of 2
edited tags
ttnphns
  • 58.8k
  • 53
  • 287
  • 512

How to calculate the distance in KNN for mixed data types?

when the data is from different types (numerical and categorical) of course euclidean distance alone or hamming distance alone can't help.
so i have 2 approaches:

  1. standardize all the data with min_max scaling, now all the numeric data are between [0,1] now we can use euclidean distance alone

  2. calculate the euclidean distance for numeric data and calculate hamming distance for categorical data, and then combine both distances(with weights)

my question is:
1-are my 2 approaches correct?if yes, then which is better?how can i combine the distances(choosing the weight for each feature)? is there an implementation of the second approach in sklearn in python?

floyd
  • 1.4k
  • 2
  • 17
  • 26