I’m looking to perform classification on data with mostly categorical features. For that purpose, Euclidean distance (or any other numerical assuming distance) doesn’t fit.
I’m looking for a kNN implementation for [R] where it is possible to select different distance methods, like Hamming distance.
Is there a way to use common kNN implementations like the one in {class} with different distance metric functions?
I’m using R 2.15
As long as you can calculate a distance/dissimilarity matrix (in whatever way you like) you can easily perform kNN classification without the need of any special package.
If anybody knows a better way of finding the most common value in a vector than the dirty line above, I’d be happy to know.
The
drop=FALSEargument is needed to preserve the subset ofNNas matrix in the casek=1. If not it will be converted to a vector andapplywill throw an error.