Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexprengere/medoids
K-medoids implementation.
https://github.com/alexprengere/medoids
clustering kmeans python
Last synced: 3 months ago
JSON representation
K-medoids implementation.
- Host: GitHub
- URL: https://github.com/alexprengere/medoids
- Owner: alexprengere
- License: apache-2.0
- Created: 2014-03-28T15:20:15.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2018-10-20T17:19:13.000Z (about 6 years ago)
- Last Synced: 2024-10-03T19:47:07.358Z (3 months ago)
- Topics: clustering, kmeans, python
- Language: Python
- Size: 31.3 KB
- Stars: 19
- Watchers: 4
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README
- License: LICENSE
Awesome Lists containing this project
README
=========
K-Medoids
=========This module implements a K-medoids algorithm using as input a list of points
and a distance function, like ``distance(p, q) = ||q - p||``:.. code-block:: python
>>> points = [1, 2, 3, 4, 5, 6, 7]
>>> def distance(a, b):
... return abs(b - a)Just import the main ``k_medoids`` function:
.. code-block:: python
>>> from medoids import k_medoids
>>> diameter, medoids = k_medoids(points, k=2, distance, spawn=2) #doctest: +SKIP
* New chosen kernels: [2, 3]
* Iteration over after 3 steps, max diameter 3
* New chosen kernels: [1, 2]
* Iteration over after 4 steps, max diameter 3
~~ Spawn end: min of max diameters 3.000 for medoids: [Medoid(2, [1, 2, 3]), Medoid(5, [4, 5, 6, 7])]There is also a ``k_medoids_auto_k`` which increases automatically the number of clusters
until we have homogeneous clusters:.. code-block:: python
>>> from medoids import k_medoids_auto_k
>>> diameter, medoids = k_medoids_auto_k(points, diam_max=3, distance, spawn=3) #doctest: +SKIP
* New chosen kernels: [2]
* Iteration over after 2 steps, max diameter 6
* New chosen kernels: [6]
* Iteration over after 2 steps, max diameter 6
* New chosen kernels: [2]
* Iteration over after 2 steps, max diameter 6
~~ Spawn end: min of max diameters 6.000 for medoids: [Medoid(4, [1, 2, 3, 4, 5, 6, 7])]
*** Diameter too big 6.000 > 3.000
*** Now trying 2 clusters* New chosen kernels: [6, 2]
* Iteration over after 2 steps, max diameter 3
* New chosen kernels: [2, 6]
* Iteration over after 1 steps, max diameter 3
* New chosen kernels: [2, 1]
* Iteration over after 3 steps, max diameter 4
~~ Spawn end: min of max diameters 3.000 for medoids: [Medoid(5, [4, 5, 6, 7]), Medoid(2, [1, 2, 3])]
*** Diameter ok 3.000 <= 3.000
*** Stopping, 2 clusters enough (7 points initially)