Skip to content

Amm4r03/knn-in-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ff3a7f0 · Dec 17, 2024

History

1 Commit
Dec 17, 2024
Dec 17, 2024
Dec 17, 2024
Dec 17, 2024

Repository files navigation

a basic implementation of the k nearest neighbors (knn) algorithm in C. Why? i dont know

usage

you can compile the code on your machine using the following command

gcc knn.c -o knn -lm

you can enter the data manually but i prefer using the command line to enter the data as well in the following format

<number_of_dimensions>
<number_of_points_in_dataset>
<dataset>

<coordinates for test point>

this format can also be seen in the input.txt file as well

this input file can be run as follows on a windows machine

knn.exe < input.txt

and the output would look as follows

5 nearest neighbors for our testpoint
point 34 | distance : 0.200000 | label : Setosa
point 32 | distance : 0.244949 | label : Setosa
point 4 | distance : 0.264575 | label : Setosa
point 9 | distance : 0.387298 | label : Setosa
point 35 | distance : 0.435890 | label : Setosa


predicted label : Setosa
freed all memory - exiting

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Languages