K-Means++
Fast KMeans++ initialization.
A scikit-learn-compatible KMeans implementation with fast SIMD distance computations and parallel centroid initialization.
fastkmeanspp is a Python package that implements a KMeans clone from
scikit-learn with a faster KMeans++ centroid
initialization. It is designed to be a drop-in replacement for
scikit-learn's KMeans when initialization is the bottleneck.
✨ Features
- Fast KMeans++ initialization: Uses optimized squared-distance computations while selecting candidate centroids.
- Portable SIMD kernels: Uses Google Highway to compile vectorized kernels for supported CPU targets and select the best implementation at runtime.
- Parallel initialization: Computes distance rows in parallel with Highway's thread pool.
- scikit-learn compatibility: Provides familiar
fit,predict,labels_,cluster_centers_, andinertia_interfaces. - SIMD Lloyd updates: Uses the same native kernels for nearest-centroid assignment, cluster accumulation, and centroid updates.
How Google Highway fits in
Google Highway is a C++ library for portable SIMD programming. The distance and clustering kernels are written once with Highway's vector operations. Highway then builds target-specific versions for the available instruction sets, such as SSE, AVX2, and AVX-512 on x86 CPUs. A small runtime dispatch layer selects the strongest target supported by the current processor and keeps a scalar fallback for portability.
The distance kernel loads several feature values at a time, subtracts the corresponding centroid values, and uses fused multiply-add operations to build the squared distance. Feature dimensions that do not fill a complete vector are handled by a short scalar tail.
During KMeans++ initialization, Highway's thread pool divides independent data rows between workers. During Lloyd updates, each worker finds the closest centroid and accumulates feature sums and point counts. The native update then turns those sums into new centroid coordinates without changing the estimator interface.
🚀 Installation
python -m pip install fastkmeanspp
🔧 Usage
import numpy as np
from fastkmeanspp import KMeans
X = np.array([[0.0, 0.0], [0.1, 0.2], [4.0, 4.0], [4.2, 3.9]])
model = KMeans(n_clusters=2, random_state=42)
model.fit(X)
print(model.labels_)
print(model.cluster_centers_)
Set n_jobs=1 for serial centroid initialization or n_jobs=-1 to use all
available threads.
Metadata
Release files for fastkmeanspp 0.5.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 11.4 MB
Release files / fastkmeanspp-0.5.6-cp314-cp314-win_arm64.whl
| Download URL | fastkmeanspp-0.5.6-cp314-cp314-win_arm64.whl |
|---|---|
| Size | 674.6 kB |
| Tags | CPython 3.14 Windows ARM64 |
|
SHA-256 checksum How to use checksums |
59ddab071b6755ccd6cf2687ec5877d698f8efcb66dc500ca715b8aae4e84b33
|
|
BLAKE2b-256 checksum How to use checksums |
3de292c29bc4f7b442b2ab7b1afc9e3fa6e7b99940732b654d5b113a591dc0af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp314-cp314-win_amd64.whl
| Download URL | fastkmeanspp-0.5.6-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
45765e9fe87a20e743d2acd39690e78034c6dfd6fc281156db7b984e4c9c82ce
|
|
BLAKE2b-256 checksum How to use checksums |
91d87d460cc3c25b24b8315305fe0a5dfa761377513c1718cbd83758f8c486b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | fastkmeanspp-0.5.6-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 280.9 kB |
| Tags | CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
daf05ed1735eac821cbdfd7c6da46265b0be4f01c615fa2011eb8e43fcfb815d
|
|
BLAKE2b-256 checksum How to use checksums |
9cc5651a7714aa0484ae9ed806f034335610ed81546787aea52fb2f4c537de54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
| Download URL | fastkmeanspp-0.5.6-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 221.6 kB |
| Tags | CPython 3.14 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
e582800ed7367fa5979d7ddb6ae30ea3eaa8d7ae03180a97550fbb604abd7c1f
|
|
BLAKE2b-256 checksum How to use checksums |
1b802e7b061620de0a31444244a2b2766374f8b9e6c1256ea101140c053817f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | fastkmeanspp-0.5.6-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 161.8 kB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0bf5b6a151be5f7590f42e3330b3aaf8660cbd94c8000edadd036fb53bbedfc4
|
|
BLAKE2b-256 checksum How to use checksums |
09620a69469c9e8d1dd394b6f22ec126a6b8462512467226be61a0338aa1dedf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp314-cp314-macosx_10_15_x86_64.whl
| Download URL | fastkmeanspp-0.5.6-cp314-cp314-macosx_10_15_x86_64.whl |
|---|---|
| Size | 229.9 kB |
| Tags | CPython 3.14 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
0342478915a94e30f2e637d30719c7a094d731a07ae6770e1e6f656bcb526ced
|
|
BLAKE2b-256 checksum How to use checksums |
0e8596ccd352a98d12ac5e844b2539f4c3e013bd211681cc5cf8d1101f7cbdd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp313-cp313-win_arm64.whl
| Download URL | fastkmeanspp-0.5.6-cp313-cp313-win_arm64.whl |
|---|---|
| Size | 654.2 kB |
| Tags | CPython 3.13 Windows ARM64 |
|
SHA-256 checksum How to use checksums |
32646a1b5783bbd1507b8a7b2c7a7b691ccb9524b98b061b79f237f315511122
|
|
BLAKE2b-256 checksum How to use checksums |
a05da3acae9708e513c308fac9e21175122324ac1955cb08856e5e205e33c881
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp313-cp313-win_amd64.whl
| Download URL | fastkmeanspp-0.5.6-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
2109e80ffb543ce2f1dc2fc850836b3399c8e45a34211fc31d4f499d0b6290e0
|
|
BLAKE2b-256 checksum How to use checksums |
b880b004646e19d6dfc0d510fac4da8c9e14f29941585a7d69f045bbff50265c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | fastkmeanspp-0.5.6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 280.9 kB |
| Tags | CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
09a0e2b4852f45ce23072736b5f0003149acc906419da964140b2022a9d9f05b
|
|
BLAKE2b-256 checksum How to use checksums |
37be14f2cd2bc98bc46d69e041e045f7f17c67a84b0f055a63b09f494e462d7c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
| Download URL | fastkmeanspp-0.5.6-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 221.5 kB |
| Tags | CPython 3.13 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
a9b388fdecdee25276c07b44265f4dea2b58689730e9ea5ea7e615761fd5a921
|
|
BLAKE2b-256 checksum How to use checksums |
f1a146c68a5f49ef212a69725ed8d92b32111cb3023029d99368d4a78d3b31e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | fastkmeanspp-0.5.6-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 161.7 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
78c7d02510984f519796ebeff6e8f2952a271001d37a81bb58ae244ee4a9a336
|
|
BLAKE2b-256 checksum How to use checksums |
3363f02d98deb4b5f95c6d45f3dee8c4d75caf534e89bdc3d44963977508e658
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp313-cp313-macosx_10_13_x86_64.whl
| Download URL | fastkmeanspp-0.5.6-cp313-cp313-macosx_10_13_x86_64.whl |
|---|---|
| Size | 229.7 kB |
| Tags | CPython 3.13 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
1cd9d8083b2c4883e2c927716cc45d905c29d1009281e196cf8493193244c16c
|
|
BLAKE2b-256 checksum How to use checksums |
46d45391fb019a2b30144b71bd3dd9997136a27f1b683364653250521cbcc2f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp312-cp312-win_arm64.whl
| Download URL | fastkmeanspp-0.5.6-cp312-cp312-win_arm64.whl |
|---|---|
| Size | 653.9 kB |
| Tags | CPython 3.12 Windows ARM64 |
|
SHA-256 checksum How to use checksums |
12cf0d3a20d5425df8d61eeb450960849ea5dd3288c741ebb1793d75bf17c5a7
|
|
BLAKE2b-256 checksum How to use checksums |
dba748bb16a9fb5b93afa1c8949fa635589e2527265712095dc12cd58f9bdc1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp312-cp312-win_amd64.whl
| Download URL | fastkmeanspp-0.5.6-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
5c630c0ad4381ab37f09f6fbbe5cd868a3f1c1e6b27ad11086c0f74bbdd704b7
|
|
BLAKE2b-256 checksum How to use checksums |
75c4e332ea4e5042ff4a7f559cec6fb38f77e1a210c4475d64e4b7796e4e7268
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | fastkmeanspp-0.5.6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 280.6 kB |
| Tags | CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
dea14c56c52ceb69fbbacac30aabc3b597708fa27f3a01406dbe7a3da7a9f1bf
|
|
BLAKE2b-256 checksum How to use checksums |
0abb51fdfc67066ee6b7aa8576aaf4817e5d52578d715ff1e26b6c392caa2875
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
| Download URL | fastkmeanspp-0.5.6-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 221.3 kB |
| Tags | CPython 3.12 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
661c0fb883435ab12b9e8fc482eb231affd122d67a11c89e9f613447b7a85ff6
|
|
BLAKE2b-256 checksum How to use checksums |
5729a051510763b43bc370ca82a550505d2a77fd511ff414b911ebb780914f4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | fastkmeanspp-0.5.6-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 161.5 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4ab5f562d5064cd602abc1691439075d328076792113f2ff1ebcdf033d719911
|
|
BLAKE2b-256 checksum How to use checksums |
8a5a64a083d63294dcc08e88a9d0c76c01ed335f474ce402926a3b2d955bd080
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp312-cp312-macosx_10_13_x86_64.whl
| Download URL | fastkmeanspp-0.5.6-cp312-cp312-macosx_10_13_x86_64.whl |
|---|---|
| Size | 229.5 kB |
| Tags | CPython 3.12 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
85d2d3eec832d9846149f15091474abde797c78eb6f6f5ee17cf3efc648bab6c
|
|
BLAKE2b-256 checksum How to use checksums |
adc46e5e80ff642946c0a86d1340d4db928a974f2d819bcc0c184c1dcb783eea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp311-cp311-win_arm64.whl
| Download URL | fastkmeanspp-0.5.6-cp311-cp311-win_arm64.whl |
|---|---|
| Size | 652.4 kB |
| Tags | CPython 3.11 Windows ARM64 |
|
SHA-256 checksum How to use checksums |
c3f9129b5c92f66b47dba91cf61c5aa4729c3bdcf7f73404248596bc296cd67c
|
|
BLAKE2b-256 checksum How to use checksums |
ac315cba7471b80f713aa8af414d11804237ff8fd08566eb49a1e9d4d589ce5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp311-cp311-win_amd64.whl
| Download URL | fastkmeanspp-0.5.6-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
fbb88326ac5dcdb56f7f246a3bf430fc718a3b0a40262f87429ba652c5a164d5
|
|
BLAKE2b-256 checksum How to use checksums |
691a917e23053ae034e403d62e154e4192ba0f094d7dee08d74d9777748bb700
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | fastkmeanspp-0.5.6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 279.4 kB |
| Tags | CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
3a26a33f6849ac2b28526922a02a6e1c82e51ef5d858f7e3a0a02e525a83db4b
|
|
BLAKE2b-256 checksum How to use checksums |
c5ca5549f0d1c96f009bd9460893c1bb8631550eea870ae74510571de6f1cf76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
| Download URL | fastkmeanspp-0.5.6-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 219.9 kB |
| Tags | CPython 3.11 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
a3f4fb11a0f52d1cfafcb10ce92add116a8798da2ba1a2bcae95c34886bb297d
|
|
BLAKE2b-256 checksum How to use checksums |
3c28d631007c0a175681e20313a00e0ae12cfecc091f3c95725c63443e6b6030
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | fastkmeanspp-0.5.6-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 159.9 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
67cb23ebc816a7b7b59303bfb6b6073517dc0a223b83fd0afd5273bbe378908d
|
|
BLAKE2b-256 checksum How to use checksums |
42bfcdebed65a664b9601bfe75a11f43d5e3d96f8fb242262e3bc48efefce2a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / fastkmeanspp-0.5.6-cp311-cp311-macosx_10_9_x86_64.whl
| Download URL | fastkmeanspp-0.5.6-cp311-cp311-macosx_10_9_x86_64.whl |
|---|---|
| Size | 229.5 kB |
| Tags | CPython 3.11 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
5b590fc6d209cd48474b1748932e96f1ab1510fcb59696f2c87dc65f54b9bbb1
|
|
BLAKE2b-256 checksum How to use checksums |
6675da04ac7e9cd8e3344f9c0d9381b447ea2364da3adfbd0388852bbd801ab8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|