Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/douglasrizzo/pydunn
Dunn index in Python
https://github.com/douglasrizzo/pydunn
Last synced: 10 days ago
JSON representation
Dunn index in Python
- Host: GitHub
- URL: https://github.com/douglasrizzo/pydunn
- Owner: douglasrizzo
- License: mit
- Created: 2024-03-16T22:57:08.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2024-08-08T18:18:44.000Z (5 months ago)
- Last Synced: 2024-12-17T19:28:30.296Z (23 days ago)
- Language: Python
- Size: 33.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dunn index in Python
An implementation of the Dunn index for internal cluster validity in Python. It sat for ages on a GitHub Gist but now it's been transferred to a proper repo.
## Usage
```py
import numpy as np
from sklearn.metrics.pairwise import euclidean_distances
from pydunn import dunn# data points and labels
data = np.array([[0, 0], [0, 1], [1, 0], [1, 1], [10, 10], [10, 14], [14, 10], [14, 14]])
labels = [0, 0, 0, 0, 1, 1, 1, 1]
distances = euclidean_distances(data)# compute the Dunn index
print("\n\n#### Dunn ####")
for diameter_method in DiameterMethod:
for cdist_method in ClusterDistanceMethod:
dunn_index = dunn(labels, distances, diameter_method, cdist_method)
print(diameter_method, cdist_method, dunn_index)
```As a bonus, you can also compute inter-cluster distances and cluster diameters separately.
```py
from pydunn import inter_cluster_distances, compute_cluster_diameters# compute inter-cluster distances
print("#### Distances ####")
for cdist_method in ClusterDistanceMethod:
print(cdist_method, "\n", inter_cluster_distances(labels, distances, cdist_method))# compute cluster diameters
print("\n\n#### Diameters ####")
for diameter_method in DiameterMethod:
print(diameter_method, compute_cluster_diameters(labels, distances, diameter_method))
```