Skip to content

adapiekarska/kmeans

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

KMeans

General description

K-Means python implementation with usage example. Coded for learning purposes.

This project contains two main files:

  • kmeans module can be used in code by incorporating it in the project and usual importing.
  • clustering_example.py is a small interactive console application created for demonstration purposes.

Getting started

Using kmeans module in your code

kmeans.py uses the numpy package, therefore you need to have it installed in your environment before running the module from your code or interpreter.

To run the k-means algorithm from this module in your code or intepreter session just call the function:

kmeans(k, data, min_vals, max_vals, max_iter=50)

with following parameters:

  • k - number of clusters,
  • d - data set, should be ndarray of shape (n, d) where n is the number of data entries, and d is the number of dimensions of each data entry,
  • min_vals, max_vals - array like lists that store min and max values for each dimension,
  • max_iter - maximal number of iterations.

kmeans() returns ndarray of shape (n, d) containing labels for every entry from the data set.

Using clustering_example.py

To see the example of clustering that utilizes kmeans module, run:

clustering_example.py

To run this example project, Python 3.6 with numpy and PIL packages installed is needed.

Copyright 2018, Ada Piekarska, All rights reserved

Releases

No releases published

Packages

No packages published

Languages