| 1 |
DESCRIPTION |
| 2 |
=========== |
| 3 |
|
| 4 |
.. image:: https://readthedocs.org/projects/python-cluster/badge/?version=latest |
| 5 |
:target: http://python-cluster.readthedocs.org |
| 6 |
:alt: Documentation Status |
| 7 |
|
| 8 |
python-cluster is a "simple" package that allows to create several groups |
| 9 |
(clusters) of objects from a list. It's meant to be flexible and able to |
| 10 |
cluster any object. To ensure this kind of flexibility, you need not only to |
| 11 |
supply the list of objects, but also a function that calculates the similarity |
| 12 |
between two of those objects. For simple datatypes, like integers, this can be |
| 13 |
as simple as a subtraction, but more complex calculations are possible. Right |
| 14 |
now, it is possible to generate the clusters using a hierarchical clustering |
| 15 |
and the popular K-Means algorithm. For the hierarchical algorithm there are |
| 16 |
different "linkage" (single, complete, average and uclus) methods available. |
| 17 |
|
| 18 |
Algorithms are based on the document found at |
| 19 |
http://www.elet.polimi.it/upload/matteucc/Clustering/tutorial_html/ |
| 20 |
|
| 21 |
.. note:: |
| 22 |
The above site is no longer avaialble, but you can still view it in the |
| 23 |
internet archive at: |
| 24 |
https://web.archive.org/web/20070912040206/http://home.dei.polimi.it//matteucc/Clustering/tutorial_html/ |
| 25 |
|
| 26 |
|
| 27 |
USAGE |
| 28 |
===== |
| 29 |
|
| 30 |
A simple python program could look like this:: |
| 31 |
|
| 32 |
>>> from cluster import HierarchicalClustering |
| 33 |
>>> data = [12,34,23,32,46,96,13] |
| 34 |
>>> cl = HierarchicalClustering(data, lambda x,y: abs(x-y)) |
| 35 |
>>> cl.getlevel(10) # get clusters of items closer than 10 |
| 36 |
[96, 46, [12, 13, 23, 34, 32]] |
| 37 |
>>> cl.getlevel(5) # get clusters of items closer than 5 |
| 38 |
[96, 46, [12, 13], 23, [34, 32]] |
| 39 |
|
| 40 |
Note, that when you retrieve a set of clusters, it immediately starts the |
| 41 |
clustering process, which is quite complex. If you intend to create clusters |
| 42 |
from a large dataset, consider doing that in a separate thread. |
| 43 |
|
| 44 |
For K-Means clustering it would look like this:: |
| 45 |
|
| 46 |
>>> from cluster import KMeansClustering |
| 47 |
>>> cl = KMeansClustering([(1,1), (2,1), (5,3), ...]) |
| 48 |
>>> clusters = cl.getclusters(2) |
| 49 |
|
| 50 |
The parameter passed to getclusters is the count of clusters generated. |
| 51 |
|
| 52 |
|
| 53 |
.. image:: https://readthedocs.org/projects/python-cluster/badge/?version=latest |
| 54 |
:target: http://python-cluster.readthedocs.org |
| 55 |
:alt: Documentation Status |