Skip to main content

Build Status License: MIT Supported Python version Stable Version

FLS++

An implementation of the FLS++ algorithm for k-means Clustering, as presented in [1]. This is an improvement of the LS++ algorithm presented by Lattanzi and Sohler in [2].

You can try FLS++ out on our Clustering Toolkit!

One can think of the algorithm as working in 3 phases:

  1. Initializing centers with k-means++ (as presented in [3]).
  2. Improving the center set by performing local search swaps (for details, see [1]).
  3. Converging the solution with LLoyd's algorithm (also known as "the" k-means algorithm).

In [2] it is shown that O(k log log k) local search iterations yield a constant factor approximation. However, in both [1] and [2] it is shown that, in practice, a very small number of iterations (e.g. 20) already yields very good results, at very reasonable runtime.

The interface is built in the same way as scikit-learn's KMeans for better compatibility.

In the following plots, we compare the performance of FLS++ (GFLS++) with various local search steps (5, 10, 15) with k-means++ (kM++), greedy k-means++ (GkM++) and the local search algorithm [2] with 25 local search steps (GLS++). The results are computed for the KDD Phy Test and the Tower datasets and averaged over 50 runs.

Boxplot Comparison for FLS++

References

[1] Theo Conrads, Lukas Drexler, Joshua Könen, Daniel R. Schmidt, and Melanie Schmidt. Local Search k-means++ with Foresight. In 22nd International Symposium on Experimental Algorithms (SEA 2024). Leibniz International Proceedings in Informatics (LIPIcs), Volume 301, pp. 7:1-7:20, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2024)

[2] Silvio Lattanzi and Christian Sohler. A better k-means++ algorithm via local search. In Proc.444 of the 36th ICML, volume 97 of Proceedings of Machine Learning Research, pages 3662–3671.445 PMLR, 09–15 Jun 2019

[3] David Arthur and Sergei Vassilvitskii. K-means++: The advantages of careful seeding. In409 Proceedings of the 18th SODA, page 1027–1035, USA, 2007

Installation

pip install flspp

Example

from flspp import FLSpp

example_data = [
    [1.0, 1.0, 1.0],
    [1.1, 1.1, 1.1],
    [1.2, 1.2, 1.2],
    [2.0, 2.0, 2.0],
    [2.1, 2.1, 2.1],
    [2.2, 2.2, 2.2],
]

flspp = FLSpp(n_clusters=2)
labels = flspp.fit_predict(example_data)
centers = flspp.cluster_centers_

print(labels) # [1, 1, 1, 0, 0, 0]
print(centers) # [[2.1, 2.1, 2.1], [1.1, 1.1, 1.1]]

Development

Install poetry

curl -sSL https://install.python-poetry.org | python3 -

Install clang

sudo apt-get install clang

Set clang variables

export CXX=/usr/bin/clang++
export CC=/usr/bin/clang

Install the package

poetry install

If the installation does not work and you do not see the C++ output, you can build the package to see the stack trace

poetry build

Run the tests

poetry run python -m unittest discover tests -v

Citation

If you use this code, please cite the following paper:

T. Conrads, L. Drexler, J. Könen, D. R. Schmidt, and M. Schmidt, "Local Search k-means++ with Foresight," in 22nd International Symposium on Experimental Algorithms (SEA 2024), 2024, pp. 7:1–7:20. doi: 10.4230/LIPIcs.SEA.2024.7.

Metadata

Release files for flspp 0.1.11

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

Source distribution (sdist)

Source distribution for flspp 0.1.11
File Size Uploaded Provenance Actions
flspp-0.1.11.tar.gz 101.0 kB With provenance Details for flspp-0.1.11.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for flspp 0.1.11
File Actions
flspp-0.1.11-cp315-cp315-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.15 CPython 3.15 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for flspp-0.1.11-cp315-cp315-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
flspp-0.1.11-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details for flspp-0.1.11-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
flspp-0.1.11-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for flspp-0.1.11-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
flspp-0.1.11-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details for flspp-0.1.11-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Total release size: 2.3 MB

Release files / flspp-0.1.11.tar.gz

Download URL flspp-0.1.11.tar.gz
Size 101.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b3dca96b35feee02f8361f38faa7a80805323553b0e2c5393a988fb0a9a3a67c
BLAKE2b-256 checksum
How to use checksums
418aa8d9c2ecb866afec574148523d2f94652f334e262a3c1e93f71638611cd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / flspp-0.1.11-cp315-cp315-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL flspp-0.1.11-cp315-cp315-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 545.0 kB
Tags CPython 3.15 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
0f13cce3b8e25a513a560a4228a42c4e6466b412ad7b828017d77156baa5fcbc
BLAKE2b-256 checksum
How to use checksums
8d69dfb8a82f248312583c178a3ccf514ac544be536054d5f23080d7e6c033d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / flspp-0.1.11-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL flspp-0.1.11-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 545.5 kB
Tags CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
e4807d38fe5b47c882f661a4906c0ce7b1994d689cb4beefabe9cbe0c0f4f559
BLAKE2b-256 checksum
How to use checksums
6069d6079ed2010ee24a67cf81ec0564595ba1218a3f78fd468568341756a067
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / flspp-0.1.11-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL flspp-0.1.11-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 545.4 kB
Tags CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b9757c9a640593f4efd2328455970c9e68ab5ce831213f782ad94313ac49bcb6
BLAKE2b-256 checksum
How to use checksums
cf238017689195a264d852a32827dee7efa941f61da43df4934e20eade0c21a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / flspp-0.1.11-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL flspp-0.1.11-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 545.3 kB
Tags CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
4bd531947bb595675dcf886d52bc13601f88fdb78543eb18c7ecd7cf10b4f37f
BLAKE2b-256 checksum
How to use checksums
a9eecc6a8844b80fc248c06e1dddde7f8097f05d801f403cb59d0a55b286c80b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Security for flspp 0.1.11

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.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for flspp-0.1.11.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

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