Clusterlets
clusterlets is a Python library collecting algorithms for fair clustering, mainly aimed at clusterlet-based
approaches. A clusterlet defines (like fair coresets and fairlets)
a clustering of data which respects some notion of fairness or balance.
Under some assumptions, (centroids of)
clusterlets can be clustered themselves achieve a fair clustering where each cluster approximately follows the original
label distribution.
Quickstart
Installation
Developed on Python 3.11.
pip install clusterlets
Getting started
import numpy
from clusterlets.extractors import RandomExtractor
# generate some data
data = numpy.random.rand(1000, 5)
labels = numpy.random.choice([0, 1], 1000, replace=True)
# creates a clusterlet extractor
extractor = RandomExtractor(random_state=42)
# extracts clusterlets, assigning a clusterlet to each data point
extracted_clusterlets = extractor.extract(data, labels, size_per_label="auto")
# you can access the data of each clusterlet!
for clusterlet in extracted_clusterlets:
print(data[clusterlet.index])
Clusterlets. The Clusterlet class implements a clusterlet, which is defined by
_id: intan id to identify itlabel_frequecies: Optional[numpy.ndarray]label frequencies associated to idcentroid: Optional[numpy.ndarray]a centroidindex: Optional[numpy.ndarray]indicating which instances of the starting data compose this clusterlet. Used in place of the data itself for a lighter object
Since clusterlets are extracted from a dataset, data[clusterlet.index] yields the data of the clusterlet.
Clusterlets support == and hash, thus can be aggregated into set[Clusterlet], and used as dictionary keys.
Extractors. Clusterlets are extracted with a set of extractors implementing the ClusterletExtractor interface
(extractors.*),
which extracts clusterlets through the extract(data, labels) method.
RandomExtractorselects random subsets of each label, then pairs them to satisfy dataset balance. One can also specify how many samples per label each clusterlet must have with a parameter dictionarysize_per_labelKMeansExtractorclusters each label separately (through K-Means), creating label-specific clusterlets. Then, matches clusterlets to achieve both clustering and balance.
The KMeansExtractor is an implementation of the ClusteringExtractor interface, which can be adapted to any
clustering algorithm by overriding the cluster(data) method.
Matchers. Matchers (extractors.matches.*) are objects which "match" existing clusterlets, creating larger ones,
i.e., they cluster clusterlets.
A Matcher implements a match(clusterlets, **kwargs) method, which is given a list of clusterings (one per
label), and a desired label balance to achieve.
Currently, we implement:
PinballMatcher, which provides matches by hoppinghopstimes through two sets of clusterlets of different labels, each hop following the clusterlet of opposite label at minimum distance.GreedyPinballMatcher, which greedily matches clusterlets maximizing some given objective:GreedyBalanceMatchermaximizes label balanceGreedyDPbMatchermaximizes clusterlet distance
CentroidMatcher, which creates a set of candidate partitions of the set of clusterlets, then scores them for balance and compactness. Note: only a subsample of sizesample_sizeis tested due to the superexponential number of possible partitions.
Metadata
Release files for clusterlets 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| clusterlets-0.0.3.tar.gz | 22.6 kB | Without provenance | Details for clusterlets-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| clusterlets-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for clusterlets-0.0.3-py3-none-any.whl |
Total release size: 48.9 kB
Release files / clusterlets-0.0.3.tar.gz
| Download URL | clusterlets-0.0.3.tar.gz |
|---|---|
| Size | 22.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
238257e3052c206197a485c356f38a3ec2db41d6fe65476cdf88da4c6a66aadd
|
|
BLAKE2b-256 checksum How to use checksums |
03c2869d7705675804231f751b283da6bcdcb5d60d5b98b5da6ed2259a2f5ec0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / clusterlets-0.0.3-py3-none-any.whl
| Download URL | clusterlets-0.0.3-py3-none-any.whl |
|---|---|
| Size | 26.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6c48d7e74948e737a29fc936ea62c02663280e0789fdafdd545a487114b5c740
|
|
BLAKE2b-256 checksum How to use checksums |
9aa3de377b92dc93f17fe0d54ef5e3d3b44d62843caa0b7bdfbcaab1d07d4440
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Security for clusterlets 0.0.3
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.