Skip to main content

Fast, eco-friendly 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.0.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.0-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.0.tar.gz.

File metadata

  • Download URL: geokmeans-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 57a02743c13e1852352c179b1c4eed27e610b567014180875d36abce4856ba49
MD5 e107dd9a16f6b747857fda2d59907823
BLAKE2b-256 225b98c6fbb23bc87cc78d077b322ee2baeb20e9c6600ded1d43f6def154f0d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for geokmeans-0.1.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7b3fbb25a36daca03d137e492e0b8fe21284fe06f6caa569fe64c97d78205868
MD5 b06d8d8dcf58ef1d75c938c3563f7502
BLAKE2b-256 1affa0528a47e849339af7d4068126d176927e30bae434f7be7acb2f3932ed76

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