Skip to main content

Torchclust: Clustering Algorithms written with Pytorch for running on GPU

License LinkedIn Twitter

Torchclust was developed to solve the issue of having to convert Pytorch Tensors to Numpy arrays and moving them to the CPU from the GPU in order to utilise frameworks such as scikit-learn.

Torchclust features implementations of common clustering algorithms with a scikit-learn feel.

Implemented algorithms

  • Centroid-based Clustering
    • KMeans
    • MeanShift
  • Density-based Clustering
    • DBSCAN
    • Gaussian Mixture Model
  • Deep / Learning-based Clustering
    • Self-Organising Maps
  • Metrics
    • Internal
      • Silhouette Score
      • Interia
      • Davies-Bouldin Index
      • Calinski-Harabasz Score / Variance Ratio Criterion
    • External
      • Purity Score
      • Rand Index
      • Adjusted Rand Index
      • Mutual Information
      • Normalised Mutual Information

Contributing

This is still an ongoing project and contributions from the opensource community are warmly welcomed.

Contributions can be made in various forms:

  • Writing docs / Updating README
  • Fixings bugs
  • More efficient implementations of algorithnms
  • Or even implementing more algorithms

Installation

Be sure the GPU version of pytorch is installed if you intend to run the algorithms on GPU.

pip install torchclust

Usage

Kmeans on gaussian blobs

import torch
import matplotlib.pyplot as plt

from torchclust.utils.datasets import make_blobs
from torchclust.centroid import KMeans

x, _ = make_blobs(1000, num_features=2, centers=3)
x = torch.from_numpy(x)

kmeans = KMeans(num_clusters=3)
labels = kmeans.fit_predict(x)

plt.scatter(x[:, 0], x[:, 1], c=labels)
plt.show()

Metadata

Release files for torchclust 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torchclust 1.0.0
File Size Uploaded
torchclust-1.0.0.tar.gz 11.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for torchclust 1.0.0
File Interpreter ABI Platform
torchclust-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.9 kB

Release files / torchclust-1.0.0.tar.gz

Download URL torchclust-1.0.0.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a70fdf7bc6479b9ea176e090d5dfc5a95157075f80e56ba98f69f418cf8dc599
BLAKE2b-256 checksum
How to use checksums
3b3fc1372599bc8b1edb48a76364112e55312c9c849fcfee3211ba830b7b09bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / torchclust-1.0.0-py3-none-any.whl

Download URL torchclust-1.0.0-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cda1d5d5a6f1dfaf949b2df83cf8a430a1b9bc347c68b6693fe36230a452b924
BLAKE2b-256 checksum
How to use checksums
9ee6b4a6b66b9013679dd8f3004d71c2828ae254fd0ba981b45bc99b2ddd7165
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page