Skip to main content

KEO

KEO logo

PyPI version Monthly downloads Python versions Tests License: MIT DOI Website Developed on Apple Silicon

A reproducible evaluation of k-means, e-means, and o-means on independent datasets.

Website and blog: https://rajveer43.github.io/keo/. Preliminary results on four datasets, plus the post Rethinking K-Means: How e-Means and o-Means Reduce Clustering Computation.

KEO is an experimental benchmarking framework for evaluating three large-scale clustering algorithms under a unified experimental protocol. It provides consistent implementations, evaluation metrics, experiment tracking, and result generation to investigate whether the performance improvements reported by recent e-means and o-means research generalize to datasets outside their original evaluations.

The goal is not to establish another leaderboard, but to conduct a controlled and reproducible investigation of algorithmic performance, computational cost, and practical limitations.

Research motivation

Recent work has proposed improvements to traditional k-means clustering:

  • k-means: The classical Lloyd algorithm, serving as the baseline.
  • e-means: A mini-batch approach using exponential moving average updates and adaptive optimization strategies, reported to achieve comparable clustering quality in substantially fewer epochs.
  • o-means: An extension of e-means that uses an inverted-file index over centroids to reduce assignment costs as the number of clusters increases.

KEO evaluates these approaches using the same datasets, initialization, evaluation metrics, and experiment-tracking infrastructure.

Algorithm Approach Reference
K — k-means Lloyd's algorithm with exact assignment and centroid updates. Lloyd (1982)
E — e-means Mini-batch k-means with EMA updates, cosine step scheduling, scaling laws, and dead-cluster revival. Bessa et al. (2026)
O — o-means e-means with a two-level inverted-file index over centroids to reduce assignment comparisons. Bajaj, Nupur, Garg (2026)

Research question

The central research question is:

Do the reported improvements of e-means and o-means generalize to datasets that were not used to develop or tune these algorithms?

Specifically, KEO investigates:

  • Whether e-means can achieve k-means-level clustering quality in approximately 1.4–2.6 epochs.
  • Whether o-means reduces assignment costs as the number of clusters increases.
  • How clustering quality, computational cost, and cluster stability change across experimental configurations.
  • Under what conditions these algorithms fail to deliver their expected improvements.

Datasets

KEO evaluates four datasets from ANN-Benchmarks. None of them appears in the evaluation dataset lists of the e-means or o-means papers, based on the papers and project materials examined for this study.

Dataset Config name Vectors (after cleaning) Dimensions Evaluation queries (val / test) Preprocessing Source file
GloVe-100 glove100 1,183,514 100 5,000 / 5,000 L2 normalization glove-100-angular
NYTimes-256 nytimes256 289,761 256 3,794 / 3,794 L2 normalization nytimes-256-angular
Fashion-MNIST fashionmnist784 60,000 784 5,000 / 5,000 none (Euclidean) fashion-mnist-784-euclidean
GIST-960 gist960 1,000,000 960 492 / 491 none (Euclidean) gist-960-euclidean

Notes:

  • GloVe-100 is the primary dataset and was run first, at three values of k (4,096 / 16,384 / 32,768). The other three were run afterwards with the same protocol: NYTimes-256 at k = 4,096 and 16,384, Fashion-MNIST at k = 2,048 and GIST-960 at k = 4,096.
  • Held-out queries are deduplicated against the training set, then split into validation and test halves with a fixed seed. NYTimes-256 lost 239 all-zero training vectors and 2,384 of its 10,000 queries this way; GIST-960 has only 1,000 queries, so its test set is small.
  • Last.fm (lastfm-64-dot) was considered and dropped: its ANN-Benchmarks file has a padding column that turns dot-product search into a Euclidean problem, so L2 k-means would measure the padding.
  • Each dataset is downloaded automatically and verified using a SHA-256 checksum recorded on the first download (ANN-Benchmarks publishes none).
  • Particle-physics and other tabular datasets (CSV, Parquet, plain HDF5 arrays) can be converted with python scripts/convert_physics_dataset.py SOURCE --out data/<name>/<name>.hdf5. The converter does a seeded train/test split and pads or truncates variable-length jets to a fixed width. A dataset YAML with source.type: local and standardize: true then z-scores each feature using the training rows only. These are feature vectors, not embeddings, so their results are reported separately (docs/ASSUMPTIONS.md A59, A60). No physics dataset has been run yet.

Installation

Requirements

  • Python 3.8 to 3.14 are supported (CI runs the tests on every one of them)
  • Python 3.12 is recommended for the development environment
  • Python 3.8 installs older library versions (for example numpy 1.24, scikit-learn 1.3, pandas 2.0), so numerical results may differ slightly in the last digits from newer Pythons. The provenance record stored with each run lists the library versions used.
  • The adapter for the official faiss E-means (faiss.contrib.e_means) needs faiss-cpu 1.16 or newer, which itself requires Python 3.10 or newer. On Python 3.8 and 3.9 that adapter reports itself as unavailable; the reference implementations and the faiss Lloyd adapter work as usual.

Install KEO using pip:

pip install keo

Development installation

Clone the repository and install dependencies using uv:

git clone https://github.com/rajveer43/keo.git
cd keo

uv sync

Quick start

Run your first experiment:

# Download the GloVe-100 dataset (~460 MB)
keo download glove100

# The other datasets: nytimes256, fashionmnist784, gist960 (GIST alone is 3.8 GB)
keo list-datasets

# Run an end-to-end smoke test
keo smoke

# Generate figures from the smoke experiment
keo figures smoke

# Check available official implementations
keo adapters

The smoke experiment runs on a small subset of the dataset and takes approximately 10 seconds.

Running experiments

Preview an experiment before execution:

keo run <name-or-path.yaml> --dry-run

Execute the experiment:

keo run <name-or-path.yaml>

Inspect experiment progress:

keo status <name>

Generate figures:

keo figures <name> --theme both

From a source checkout, prefix commands with uv run. For example:

uv run keo smoke
uv run pytest

Data and results

KEO uses configurable directories for datasets, results, and experiment configurations.

Environment variable Purpose
KEO_DATA_DIR Dataset storage
KEO_RESULTS_DIR Experiment results
KEO_CONFIGS_DIR Experiment configurations

By default:

  • Source installations use data/ and results/ within the repository.
  • Installed packages cache datasets in ~/.cache/keo/data.
  • Results are written to ./results relative to the current working directory.

Methodology

Implementation strategy

Each algorithm is evaluated through two separate implementations.

1. Reference implementation

Our own PyTorch CPU implementations, developed from the corresponding research papers.

2. Official implementation

The authors' released implementations, accessed through isolated worker processes and adapters, including Faiss contrib/e_means.

These implementations are never mixed within an experiment. Every result records its implementation provenance.

Clustering quality is compared across implementations. Wall-clock execution time is compared only within the same implementation to avoid misleading performance comparisons.

Evaluation metrics

KEO tracks the following metrics:

Metric Description
MSE Mean squared L2 distance to the assigned centroid, evaluated on training and held-out points.
Relative MSE (Gap) Error relative to k-means run for 25 iterations from the same initialization and random seed.
Cluster health Dead clusters, empty clusters, and Faiss imbalance factor.
Computational cost Distance computations for assignment and index maintenance.
Wall-clock time Fitting time, compared within the same implementation.

MSE is computed using exact assignment in float64 precision on both training and held-out points.

Computational cost is reported in two forms:

  • Actual distance computations performed.
  • Nominal cell arithmetic.

This provides a hardware-independent perspective on algorithmic complexity.

e-means configurations

KEO supports two e-means recipes:

  • official: Uses the constants provided by the official implementation. This is the default configuration.
  • paper: Uses the values specified in the research paper.

The two configurations differ slightly. All headline evaluations use the official recipe.

Reproducibility and experiment tracking

Reproducibility is a central design principle of KEO.

Each experiment result is associated with a content hash derived from its configuration.

This provides several benefits:

  • Experiments can resume after interruption.
  • Previously completed result cells are not recomputed.
  • Configuration provenance is preserved.
  • Results remain traceable to their corresponding experimental settings.

Figures and reporting

KEO generates six figures directly from stored experiment results.

Each figure includes:

  • A corresponding CSV containing the exact plotted values.
  • Light and dark theme variants.
  • Data-driven headline calculations.

No headline metrics are manually entered into the figures.

Project status

KEO is under active development. The experimental infrastructure and core algorithm implementations are complete, while the main benchmark and analysis phases remain in progress.

Phase Scope Status
0–2 Specification, dataset pipeline, metrics, k-means Complete
3–4 e-means and o-means reference implementations Complete
5 Official implementation adapters Complete
6 Result storage, resumable execution, figure generation Complete
7 Full benchmark grid In progress: GloVe-100 at full size (k = 4,096 / 16,384 / 32,768, 3 seeds, 252 cells) and NYTimes-256, Fashion-MNIST and GIST-960 at full size (3 seeds, 336 cells) are complete; GloVe-100 subsets (n = 100k to 1M) and seeds 3–9 not run
8 Analysis and report generation Not started
9 Ablations, scaling-law transfer, secondary experiments Not started
10 Hardening and packaging Not started

Current validation

  • 179 automated tests passing on the development machine.
  • Smoke experiment covering 26 experimental cells.
  • Successful end-to-end execution of the smoke pipeline.
  • GitHub Actions CI badge tracks the latest Linux test run.

Implementation agreement

On GloVe subsets, the reference e-means implementation matches the official implementation within approximately 0.2% on held-out error.

In the full runs, the two agree within 0.26% on GloVe-100 and within 0.70% on the other datasets at integer pass budgets. At fractional budgets (1.5 and 12.8 passes) they differ by up to 1.95%, so the 0.5% parity target is not met there on GloVe-100, NYTimes-256 (k = 16,384) or Fashion-MNIST. The suspected cause is a difference in the fractional-pass schedule, plus the remainder rows the reference drops from every epoch, but this has not been isolated by an experiment.

Preliminary results

Median over 3 seeds, GloVe-100, NYTimes-256, Fashion-MNIST and GIST-960, Apple M4 CPU:

  • e-means reaches the quality of 25 Lloyd iterations in about 1.4 to 3.2 passes over the data. The number needed depends on the dataset (NYTimes-256 at k = 16,384 needed about 3.1 to 3.2).
  • o-means (our reconstruction) needs far fewer distance computations on GloVe-100 at larger k (0.26 full scans at k = 16,384 and 0.14 at k = 32,768, against 1.90 and 1.77 for e-means), a moderate amount on Fashion-MNIST and GIST-960, and little on NYTimes-256 (2.24 against 3.04 scans at k = 16,384). The reason for the NYTimes-256 result is not yet known.

The full table and discussion are in the blog post (section 11) and in results/cross_dataset/tables/match_lloyd25.csv.

Important: these are preliminary results, not benchmark conclusions. There are three seeds per configuration, no significance tests, one machine, and the o-means numbers are for our reconstruction. Dataset size, dimension and k differ between datasets, so a difference between datasets cannot be put down to the data alone.

Results in results/smoke/ are based on two repetitions at k = 512. They validate the experimental pipeline and should not be interpreted as answers to the research question.

Limitations

The current evaluation has several limitations that should be considered when interpreting its results.

1. o-means reconstruction

The o-means paper has not been released. Its implementation is reconstructed using the available project page, with unspecified details documented as explicit assumptions. Conclusions about o-means therefore apply to this reconstruction.

2. Hardware limitations

The reference development environment uses an Apple M4 CPU without GPU execution for the reference implementations. GPU performance claims from the original papers cannot currently be reproduced in this environment.

Clustering quality and computational operation counts can still be evaluated.

3. CPU timing limitations

Index maintenance in o-means may have different performance characteristics on GPUs and CPUs. Consequently, CPU wall-clock measurements should not be treated as a definitive assessment of the algorithm's performance.

4. Dataset coverage

The current evaluation uses four ANN-Benchmarks datasets (GloVe-100, NYTimes-256, Fashion-MNIST, GIST-960), all image or text-derived vectors. Results may not generalize to other kinds of data, such as sentence or multimodal embeddings or particle-physics features. Evaluating further datasets is tracked in the issue tracker.

5. Dataset novelty

The claim that these datasets are independent is bounded to the dataset lists examined in the two papers. It is not a claim that they have never been used in previous clustering research. GIST-960 is a different dataset from the SIFT descriptors used in the e-means paper, but both are image descriptors.

Repository structure

keo/
├── configs/              # Dataset and experiment configurations
├── src/
│   └── keo/
│       ├── algos/        # k-means, e-means, o-means
│       │   └── adapters/ # Official implementation adapters
│       ├── bench/        # Experiment runner and result storage
│       ├── metrics/      # Evaluation metrics and operation counting
│       ├── analysis/     # Figure generation and analysis
│       └── data/         # Download, verification, preparation
├── scripts/              # Benchmark runners and the cross-dataset table
├── tests/                # Unit and phase-gate tests
├── results/              # Experiment outputs
├── blog/                 # Hugo site (landing page and blog post)
├── CONTRIBUTING.md
├── CODE_OF_CONDUCT.md
├── SECURITY.md
├── CHANGELOG.md
└── LICENSE

References

Clustering algorithms

  • e-means: Bessa et al. (2026). e-means: Outperforming k-means (in one-tenth the epochs). Paper · Project page
  • o-means: Bajaj, Nupur, Garg (2026). o-means: Index the centroids, don't scan them. Project page, November 2026. Paper not yet released.
  • Flash-KMeans: GPU k-means baseline. arXiv:2603.09229
  • Faiss: Douze et al. (2024). arXiv:2401.08281

Classical foundations

  • Lloyd (1982). Least squares quantization in PCM.
  • Arthur and Vassilvitskii (2007). k-means++: The advantages of careful seeding.
  • Sculley (2010). Web-scale k-means clustering.

Contributing

Contributions are welcome, and you do not need to write code to help. Running the benchmark on a GPU, suggesting a dataset, or reviewing the o-means reconstruction are all useful. See CONTRIBUTING.md for how to set up, what a good pull request looks like, and the rules that keep the benchmark trustworthy. Please follow the Code of Conduct. To report a security problem, see SECURITY.md.

If you use KEO in your work, please cite it using CITATION.cff or the DOI badge above.

License

KEO is released under the MIT License.

The datasets are not redistributed with the package. They are downloaded from ANN-Benchmarks and remain subject to their respective terms.


KEO — Reproducible clustering research.
Built for transparent, controlled, and reproducible evaluation.

Metadata

Release files for keo 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keo 0.1.5
File Size Uploaded Provenance Actions
keo-0.1.5.tar.gz 93.6 kB Without provenance Details for keo-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for keo 0.1.5
File Interpreter ABI Platform Actions
keo-0.1.5-py3-none-any.whl Python 3 none any Details for keo-0.1.5-py3-none-any.whl

Total release size: 182.6 kB

Release files / keo-0.1.5.tar.gz

Download URL keo-0.1.5.tar.gz
Size 93.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fa5bd5693161196c0e87d0ec9a07a866892686af90fbb0a8850d6beba8acdd06
BLAKE2b-256 checksum
How to use checksums
e10be3420f480a344e7ea60451d89df17e4e99df53edc0bc8edd34e0e37750d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / keo-0.1.5-py3-none-any.whl

Download URL keo-0.1.5-py3-none-any.whl
Size 89.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b624fdcaeec5d8f30dcae394235e296127dd3815c46a61600176866c4cfba90c
BLAKE2b-256 checksum
How to use checksums
43839ac36f5368e0ba731ec0c07c344511968a4a5557d42cbbdd00c8aa697792
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for keo 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page