Skip to content

amrukwa/kmeans_cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodeFactor BCH compliance

kmeans_cpp

K-Means algorithm implementation in C++

Tools

  1. Vectors - provides class and functions for operations on matrices
  2. initialization - entails functions choosing some part of given vectors (random or k++ initialization)
  3. kmeans - runs k-means algorithm
  4. dunn - runs k-means algorithm with sweep by Dunn index
  5. silhouette - runs k-means algorithm with sweep by Silhouette Score
  6. sorting - sorts two vectors in descending order of one of them
  7. pca - performs dimension reduction by Principal Component Analysis

Exemplary usage

You can use this implementation as shown here.

Parameters

Distance

In this version the used distance metric can be chosen from Euclidean, correlation and cityblock distance.

Initialization

The default initialization method is set to k++, however it is possible to choose MacQueen's random method as well.

Inter and intra distances

Dunn Index relies on the choice of the appropriate inter and intra distance measurement types. For distance between clusters the available metrics are: centroid, closest, furthest, avg, while for distance within cluster: centroid, furthest, avg.

The data file

I prepared a special constructor for matrices that loads the data from the specified stream. You can find it in Vectors.h. The usage is shown in the exemplary file. You can use as many samples and features as you wish - the program will take care of the dimensions. You should not place the number of desired clusters in this file - choose it while creating kmeans instance or let it be done by Dunn or Silhouette. Default minimum and maximum numbers of clusters for these scores are 2 and 20 respectively. In the following lines of the file insert points coordinates, don't use commas. The delimiter is set to space. You can use exponential notation. Every line, including the last line, should be ended with enter. This version doesn't check if your file is correctly prepared for overall shorter execution time. This can lead to unexpected errors in case of incorrect file.

About

K-Means algorithm implementation in C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published