Skip to content

exTerEX/kmeans

Repository files navigation

KMeans

A fast k-means clustering algorithm implemented in C with Python bindings.

Installation

Using UV (recommended)

uv pip install .

Using pip

pip install .

Development installation

uv pip install -e ".[dev]"

Quick Start

import numpy as np
from kmeans import KMeans, kmeans

# Generate sample data
np.random.seed(42)
data = np.vstack([
    np.random.randn(100, 2) + [0, 0],
    np.random.randn(100, 2) + [5, 5],
    np.random.randn(100, 2) + [10, 0],
])

# Using the functional API
centroids, labels = kmeans(data, k=3)

# Using the class-based API
model = KMeans(n_clusters=3)
model.fit(data)
predictions = model.predict(data)

Features

  • Fast k-means clustering with C implementation
  • K-means++ initialization
  • NumPy integration
  • Scikit-learn compatible API
  • Support for arbitrary dimensions

License

MIT