Skip to main content

python-cluster is a "simple" package that allows to create several groups (clusters) of objects from a list

Project description

DESCRIPTION

python-cluster is a “simple” package that allows to create several groups (clusters) of objects from a list. It’s meant to be flexible and able to cluster any object. To ensure this kind of flexibility, you need not only to supply the list of objects, but also a function that calculates the similarity between two of those objects. For simple datatypes, like integers, this can be as simple as a subtraction, but more complex calculations are possible. Right now, it is possible to generate the clusters using a hierarchical clustering and the popular K-Means algorithm. For the hierarchical algorithm there are different “linkage” (single, complete, average and uclus) methods available. I plan to implement other algoithms as well on an “as-needed” or “as-I-have-time” basis.

Algorithms are based on the document found at http://www.elet.polimi.it/upload/matteucc/Clustering/tutorial_html/

USAGE

A simple python program could look like this:

>>> from cluster import *
>>> data = [12,34,23,32,46,96,13]
>>> cl = HierarchicalClustering(data, lambda x,y: abs(x-y))
>>> cl.getlevel(10)     # get clusters of items closer than 10
[96, 46, [12, 13, 23, 34, 32]]
>>> cl.getlevel(5)      # get clusters of items closer than 5
[96, 46, [12, 13], 23, [34, 32]]

Note, that when you retrieve a set of clusters, it immediately starts the clustering process, which is quite complex. If you intend to create clusters from a large dataset, consider doing that in a separate thread.

For K-Means clustering it would look like this:

>>> from cluster import KMeansClustering
>>> cl = KMeansClustering([(1,1), (2,1), (5,3), ...])
>>> clusters = cl.getclusters(2)

The parameter passed to getclusters is the count of clusters generated.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cluster-1.1.2.tar.gz (38.7 kB view details)

Uploaded Source

Built Distribution

cluster-1.1.2.linux-i686.exe (192.1 kB view details)

Uploaded Source

File details

Details for the file cluster-1.1.2.tar.gz.

File metadata

  • Download URL: cluster-1.1.2.tar.gz
  • Upload date:
  • Size: 38.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cluster-1.1.2.tar.gz
Algorithm Hash digest
SHA256 6b12e49623eab1a53c7f9375663576ccc3ac366ff2e26a94863c897bdb3c30f0
MD5 2f90415ef6c3ae08db815e5dcb051bf5
BLAKE2b-256 f1eab00317c74e283099d46ce23b5dd84d109fe5297f9f4a0483e33e0567ac0b

See more details on using hashes here.

File details

Details for the file cluster-1.1.2.linux-i686.exe.

File metadata

File hashes

Hashes for cluster-1.1.2.linux-i686.exe
Algorithm Hash digest
SHA256 acc74ecd406228f3a353ae96372a659065778348f8eae884d48654bb2dfc769c
MD5 7256ab7a1d693f09833e97f8af5428fc
BLAKE2b-256 36562f5601a26104b1c0fe552b236cd569e0029afebe8569ca963374d79b699a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page