Skip to main content

Mini-batch k-means clustering implemented in PyTorch

Project description

minibatch-kmeans

This package implements mini-batch k-means following Sculley (WWW 2010) (Web-Scale K-Means Clustering). scikit-learn's MiniBatchKMeans is based on the same algorithm but is CPU-only; this library is for PyTorch pipelines that want native tensors and GPU acceleration.

Requirements

  • Python 3.10+ (see pyproject.toml)
  • PyTorch 2.x (torch>=2.0; use pytorch.org for the wheel that matches your platform / CUDA).

Installation

pip install minibatch-kmeans

Quick start

import torch
from minibatch_kmeans import MiniBatchKMeans

X = torch.randn(5000, 4, dtype=torch.float32)
km = MiniBatchKMeans(n_clusters=8, dtype=torch.float32)
km.fit(X, batch_size=256, max_iter=20)
labels = km.predict(X)

Incremental training

km = MiniBatchKMeans(n_clusters=8, dtype=torch.float32)
for batch in X.split(256):
    km.partial_fit(batch)
labels = km.predict(X)

Example notebook: notebooks/partial_fit_demo.ipynb

Documentation

API reference: mb-14.github.io/minibatch-kmeans

Benchmarks & evaluation

See evaluation/README.md for benchmarks and evaluation.

Development

pip install -e ".[dev]"
python -m unittest discover -s tests -v

Generate local API docs (HTML in pdoc_html/):

bash scripts/gen_api_docs.sh

Related projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

minibatch_kmeans-0.1.1.tar.gz (24.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

minibatch_kmeans-0.1.1-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file minibatch_kmeans-0.1.1.tar.gz.

File metadata

  • Download URL: minibatch_kmeans-0.1.1.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for minibatch_kmeans-0.1.1.tar.gz
Algorithm Hash digest
SHA256 715baa29bbd262a98eba1b75161f7115c4d80d39f315bb91c1c6163adb67fc90
MD5 3865f31f5a19e293d6dcbf1ea0042c71
BLAKE2b-256 216f492831d9bdf5cd952b7ba0ddf57fd450d6114b0d9db98bd64732c7a121aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for minibatch_kmeans-0.1.1.tar.gz:

Publisher: publish.yml on mb-14/minibatch-kmeans

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file minibatch_kmeans-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for minibatch_kmeans-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9c1502abdd7bead178ae171d291a6099d47e9fecde00f3f1ee5ca56a99d88179
MD5 80d42e2ce93d6c1439241896373f5b1e
BLAKE2b-256 60856f8bc972b53b67a15d87c036198c51d53d0a1d192eaef63f7062b6824f6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for minibatch_kmeans-0.1.1-py3-none-any.whl:

Publisher: publish.yml on mb-14/minibatch-kmeans

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page