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.2.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.2-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.2.tar.gz.

File metadata

  • Download URL: geokmeans-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 37c4abe8f5e8b64a2adb9b07f320b395db34f4856c07e7db7f6b73f22881ea4f
MD5 819b46e8da0641fb39de937202fa5b29
BLAKE2b-256 dbefd22e88e6257d587a9228f7ac242ddf7ef4c848975fb86e7dcf14fac2fef0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for geokmeans-0.1.2-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 2d24a6445139ee029256cca3902cd9231cf3f76d5823b4d404c24692a7700384
MD5 9175430dab75187547c7619a0cf6f627
BLAKE2b-256 838997ac7f61a0f66eeade8bd480bbb09b525361be50923987ce522338a8f059

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