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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
715baa29bbd262a98eba1b75161f7115c4d80d39f315bb91c1c6163adb67fc90
|
|
| MD5 |
3865f31f5a19e293d6dcbf1ea0042c71
|
|
| BLAKE2b-256 |
216f492831d9bdf5cd952b7ba0ddf57fd450d6114b0d9db98bd64732c7a121aa
|
Provenance
The following attestation bundles were made for minibatch_kmeans-0.1.1.tar.gz:
Publisher:
publish.yml on mb-14/minibatch-kmeans
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
minibatch_kmeans-0.1.1.tar.gz -
Subject digest:
715baa29bbd262a98eba1b75161f7115c4d80d39f315bb91c1c6163adb67fc90 - Sigstore transparency entry: 1238719198
- Sigstore integration time:
-
Permalink:
mb-14/minibatch-kmeans@151c12eec12746c093b8ecdba1edeaedfd11b8fe -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mb-14
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@151c12eec12746c093b8ecdba1edeaedfd11b8fe -
Trigger Event:
push
-
Statement type:
File details
Details for the file minibatch_kmeans-0.1.1-py3-none-any.whl.
File metadata
- Download URL: minibatch_kmeans-0.1.1-py3-none-any.whl
- Upload date:
- Size: 25.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c1502abdd7bead178ae171d291a6099d47e9fecde00f3f1ee5ca56a99d88179
|
|
| MD5 |
80d42e2ce93d6c1439241896373f5b1e
|
|
| BLAKE2b-256 |
60856f8bc972b53b67a15d87c036198c51d53d0a1d192eaef63f7062b6824f6f
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
minibatch_kmeans-0.1.1-py3-none-any.whl -
Subject digest:
9c1502abdd7bead178ae171d291a6099d47e9fecde00f3f1ee5ca56a99d88179 - Sigstore transparency entry: 1238719200
- Sigstore integration time:
-
Permalink:
mb-14/minibatch-kmeans@151c12eec12746c093b8ecdba1edeaedfd11b8fe -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mb-14
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@151c12eec12746c093b8ecdba1edeaedfd11b8fe -
Trigger Event:
push
-
Statement type: