Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.
/ kmedoids Public archive

[Unmaintained] The Python implementation of k-medoids.

Notifications You must be signed in to change notification settings

letiantian/kmedoids

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

kmedoids

The Python implementation of k-medoids.

Example

from sklearn.metrics.pairwise import pairwise_distances
import numpy as np

import kmedoids

# 3 points in dataset
data = np.array([[1,1], 
                [2,2], 
                [10,10]])

# distance matrix
D = pairwise_distances(data, metric='euclidean')

# split into 2 clusters
M, C = kmedoids.kMedoids(D, 2)

print('medoids:')
for point_idx in M:
    print( data[point_idx] )

print('')
print('clustering result:')
for label in C:
    for point_idx in C[label]:
        print('label {0}: {1}'.format(label, data[point_idx]))

Output:

medoids:
[1 1]
[10 10]

clustering result:
label 0: [1 1]
label 0: [2 2]
label 1: [10 10]

License

This code is from:

Bauckhage C. Numpy/scipy Recipes for Data Science: k-Medoids Clustering[R]. Technical Report, University of Bonn, 2015.

Please cite the article if the code is used in your research.

About

[Unmaintained] The Python implementation of k-medoids.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages