A KNN implemention in Java.
- Clone the project.
- Using eclipse, select
File > Import.UnderMaven, chooseExisting Maven Projects. - Point to the directory where the
pom.xmlis stored. - Select the project and then
Finish. - Install dependencies and build with
Right click on the project > Run as > Maven install.
Using the project is very straightforward:
try {
KNN knn = new KNN(5, new EuclideanDistance());
knn.run(KNN.ARFF_FILE_PATH);
knn.printResult();
} catch (IOException e) {
// file issues
}We use Apache's DistanceMeasure interface. Therefore, we support any implementation, including these out-of-the-box:
| Distance function | Call |
|---|---|
| Euclidean | new EuclideanDistance() |
| Canberra | new CanberraDistance() |
| Chebyshev | new ChebyshevDistance() |
| Earth mover's | new EarthMoversDistance() |
| Manhattan | new ManhattanDistance() |