Skip to content

KNN and K-Means Algorithms implementation in Cpp with STL containers

License

Notifications You must be signed in to change notification settings

sanoguzhan/Algorithms-in-Cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ML-Algorithms-in-C++

This repo compares KNN and K-Means Machine Learning Algorithms which were implemented by using only standard templates in C++. The motivation behid of this project to implement the algorithms from strach to grasp better understanding of them and compare the results.

Keywords: C++, Machine Learning, STL, Algorithms, Docker, Bash Script

License

Algorithms:

  • KNN: The k-nearest neighbors algorithm is a supervised classification algorithm. The first step in this algorithm to transform data points into feature vectors then finding the distance between the mathematical values of these points.

    KNN runs this formula to compute the distance between each data point and the test data. It then finds the probability of these points being similar to the test data and classifies it based on which points share the highest probabilities.

  • K-Means: The k-means algorithm is an unsupervised clustering algorithm. It takes unlabeled points and tries to group them into “k” number of clusters.

Performance:

-> The data structures used is mainly vector, set, map. The vector contains pointer to data which data is commonly used and copied over each algorithm in order to boost the performance.

-> On the implementation of this project KNN algorithm runs in a loop to find the best k and performs about 97% accurancy. K-Means algorithm also runs in a loop in order to find the best k and performs worse than KNN. Running time comperension is that KNN is very slower compared to K-Means. It would be interesting to implement them with CUDA and check the performance.

How to Run

Without Docker

  • clone the repo

  • cd to directory

  • run chmod +x run.sh && ./run.sh

  • Note:

    This will work only with linux or Mac, and requires clang installed

With Docker

  • cd docker
  • docker-compose build
  • docker-compose run ml-runner bash
  • run chmod +x run.sh && ./run.sh
  • It will prompt for the algorithm name

Class Diagram

Links for Help:

About

KNN and K-Means Algorithms implementation in Cpp with STL containers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published