Created
January 31, 2014 22:02
-
-
Save glesica/8744176 to your computer and use it in GitHub Desktop.
Minimal KNN implementation in Julia.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using StatsBase | |
function knn(k, train, classes, obs) | |
nearest = sortperm(vec(sqrt(sum(broadcast((a, b) -> (a-b)^2, obs, train), 2))))[1:k] | |
return mode(classes[nearest]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment