Debian Codegraph @

docs/index.rst

raw
1 Welcome to python-cluster's documentation!
2 ==========================================
3
4 Index
5 -----
6
7 .. toctree::
8 :maxdepth: 1
9
10 changelog
11
12
13 Introduction
14 ------------
15
16 Implementation of cluster algorithms in pure Python.
17
18 As this is exacuted in the Python runtime, the code runs slower than similar
19 implementations in compiled languages. You gain however to run this on pretty
20 much any Python object. The different clustering methods have different
21 prerequisites however which are mentioned in the different implementations.
22
23
24
25 Example for K-Means Clustering
26 ------------------------------
27
28 ::
29
30 from cluster import KMeansClustering
31 data = [
32 (8, 2),
33 (7, 3),
34 (2, 6),
35 (3, 5),
36 (3, 6),
37 (1, 5),
38 (8, 1),
39 (3, 4),
40 (8, 3),
41 (9, 2),
42 (2, 5),
43 (9, 3)
44 ]
45 cl = KMeansClustering(data)
46 cl.getclusters(2)
47
48 The above code would give the following result::
49
50 [
51 [(8, 2), (8, 1), (8, 3), (7, 3), (9, 2), (9, 3)],
52 [(3, 5), (1, 5), (3, 4), (2, 6), (2, 5), (3, 6)]
53 ]
54
55
56 Example for Hierarchical Clustering
57 -----------------------------------
58
59 ::
60
61 from cluster import HierarchicalClustering
62 data = [791, 956, 676, 124, 564, 84, 24, 365, 594, 940, 398,
63 971, 131, 365, 542, 336, 518, 835, 134, 391]
64 cl = HierarchicalClustering(data)
65 cl.getlevel(40)
66
67 The above code would give the following result::
68
69 [
70 [24],
71 [84, 124, 131, 134],
72 [336, 365, 365, 391, 398],
73 [676],
74 [594, 518, 542, 564],
75 [940, 956, 971],
76 [791],
77 [835],
78 ]
79
80
81 Using :py:meth:`~cluster.method.hierarchical.HierarchicalClustering.getlevel()`
82 returns clusters where the distance between each cluster is no less than
83 *level*.
84
85 .. note::
86
87 Due to a bug_ in earlier releases, the elements of the input data *must be*
88 sortable!
89
90 .. _bug: https://github.com/exhuma/python-cluster/issues/11
91
92
93 API
94 ---
95
96 .. toctree::
97 :maxdepth: 1
98
99 apidoc/cluster
100 apidoc/cluster.matrix
101 apidoc/cluster.method.base
102 apidoc/cluster.method.hierarchical
103 apidoc/cluster.method.kmeans
104 apidoc/cluster.util
105
106 Indices and tables
107 ==================
108
109 * :ref:`genindex`
110 * :ref:`modindex`
111 * :ref:`search`
112