Coder Social home page Coder Social logo

clustering-code's Introduction

Clustering-Code

Repository to Hold onto Various Clustering Tools.

##Contents ###kmeans.py

K-Means Clustering Code.

####Methods:

#####comparison(data, means):

How the data is clustered. Computes the euclidian distance between a data point and each mean, then finds the minimum. Using the argmin function, this method finds the minimum for every point in data and returns an array of cluster indecies. Cluster indecies are values whose index matches an index in data and whose values designate the cluster to which it belongs.

Returns: clusters, means

#####kmeans(data, means):

Basic K-means clustering method. Takes in an NxM matrix of data points, and an KxM matrix of means. Returns a list of K subsets of data (i.e. clusters), each subset is of the same form as data.

#####kmeans_struct(data, means):

This works similarly to kmeans, but instead of a matrix input, this method takes numpy structured arrays. The data and means must have the same dtype. Returns a list of K subsets of data (clusters), each with the same dtype as data.

Returns: clusters, means

#####arg_[METHOD]

Any method beginning with 'arg_' returns the array of cluster indecies rather than the clusters themselves. Useful for clustering data sets in which all columns do not need to be clustered.

Returns: cluster indecies, means

####Examples:

>>> from kmeans import *
>>> import numpy as np
>>> Data = np.arange(50).reshape((10,5))
>>> Means = np.arange(15).reshape((3,5))
>>> Means
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14]])
>>> clusters, means = kmeans(Data, Means)
>>> clusters.shape
(3,)
>>> clusters[0]
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14]])
>>> means.shape
(3, 5)
>>> means
array([[  5. ,   6. ,   7. ,   8. ,   9. ],
       [ 20. ,  21. ,  22. ,  23. ,  24. ],
       [ 37.5,  38.5,  39.5,  40.5,  41.5]])

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.