Skip to main content

Accelerated, compute efficient k-means clustering (Geometric-k-means and six other accelerated variants), with a scikit-learn-style API.

Project description

geokmeans

Fast, eco-friendly k-means clustering for Python. A thin, scikit-learn-style wrapper over a C++ library implementing seven k-means algorithms — including Geometric-k-means, the bound-free method from Sharma et al. (2026).

All seven algorithms return the same Lloyd's k-means solution; they differ in how aggressively they prune distance computations, so you get identical results with far less work.

Algorithm algorithm=
Geometric-k-means "geo" (default)
Lloyd's "lloyd"
Elkan "elkan"
Hamerly "hamerly"
Annulus "annulus"
Exponion "exponion"
Ball k-means++ "ball"

Installation

pip install geokmeans

Prebuilt wheels are published for Linux, macOS, and Windows (CPython 3.9–3.13), so no compiler is required on common platforms.

Quickstart

import numpy as np
from geokmeans import GeoKMeans

X = np.random.default_rng(0).random((1000, 20))

km = GeoKMeans(n_clusters=8, algorithm="geo", random_state=0).fit(X)

km.labels_                     # cluster index per point  (n_samples,)
km.cluster_centers_            # centroids                (n_clusters, n_features)
km.n_iter_                     # iterations to convergence
km.n_distance_calculations_    # distance computations performed

km.predict(np.random.random((5, 20)))   # assign new points

The API mirrors scikit-learn (fit, predict, fit_predict, cluster_centers_, labels_, n_iter_), so it drops into existing pipelines.

Long-running jobs

The compute runs in C++ with the GIL released, so a long fit won't freeze the interpreter and you can run it off the main thread:

from concurrent.futures import ProcessPoolExecutor

def cluster(X):
    return GeoKMeans(n_clusters=50, algorithm="geo", random_state=0).fit(X)

with ProcessPoolExecutor() as pool:
    result = pool.submit(cluster, X).result()

Pass verbose=True to stream convergence progress.

Citation

If you use this package, please cite:

Sharma, P., Stanislaw, M., Kurban, H., Kulekci, O., & Dalkilic, M. (2026). Geometric-k-means: A Bound Free Approach to Fast and Eco-Friendly k-means. Machine Learning, 115(2), 30. https://doi.org/10.1007/s10994-025-06891-1

Documentation

Full documentation: https://parichit.github.io/Geometric-k-means/

License

Apache-2.0. See LICENSE.

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

geokmeans-0.1.1.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

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

geokmeans-0.1.1-cp310-cp310-macosx_14_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: geokmeans-0.1.1.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for geokmeans-0.1.1.tar.gz
Algorithm Hash digest
SHA256 83dade9adf07d3e4d032ca1e7ac6f21f6a4db01f6ba63c40589341a209d1657c
MD5 23ae8ff02f251456c1098d73f4c00a6f
BLAKE2b-256 d3f72231d0d91aaceff1c0aa15b68a5fb9ec4f319e36e397a76f3328ba68c608

See more details on using hashes here.

File details

Details for the file geokmeans-0.1.1-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for geokmeans-0.1.1-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 28b5271f073a3c12035f6df505b4c61ff7aa04d323cc78497ded977a55f2aea7
MD5 bd6d5beb8baa6081afdd8cad9609f492
BLAKE2b-256 10ebd692026965037ec9d41243550eec668cc26bcc90c38e25fc6f788db5c059

See more details on using hashes here.

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