Skip to main content

Generic Anti-Clustering

Project description

Anti-clustering

A generic Python library for solving the anti-clustering problem. While clustering algorithms will achieve high similarity within a cluster and low similarity between clusters, the anti-clustering algorithms will achieve the opposite; namely to minimise similarity within a cluster and maximise the similarity between clusters. Currently, a handful of algorithms are implemented in this library:

  • An exact approach using a BIP formulation.
  • An enumerated exchange heuristic.
  • A simulated annealing heuristic.

Keep in mind anti-clustering is computationally difficult problem and may run slow even for small instance sizes. The current ILP does not finish in reasonable time when anti-clustering the Iris dataset (150 data points).

The two former approaches are implemented as describing in following paper:
Papenberg, M., & Klau, G. W. (2021). Using anticlustering to partition data sets into equivalent parts. Psychological Methods, 26(2), 161–174. DOI. Preprint
The paper is accompanied by a library for the R programming language: anticlust.

Differently to the anticlust R package, this library currently only have one objective function. In this library the objective will maximise intra-cluster distance: Euclidean distance for numerical columns and Hamming distance for categorical columns.

Use cases

Within software testing, anti-clustering can be used for generating test and control groups in AB-testing. Example: You have a webshop with a number of users. The webshop is undergoing active development and you have a new feature coming up. This feature should be tested against as many different users as possible without testing against the entire user-base. For that you can create a maximally diverse subset of the user-base to test against (the A group). The remaining users (B group) will not test this feature. For dividing the user-base you can use the anti-clustering algorithms. A and B groups should be as similar as possible to have a reliable basis of comparison, but internally in group A (and B) the elements should be as dissimilar as possible.

This is just one use case, probably many more exists.

Usage

The input to the algorithm is a Pandas dataframe with each row representing a data point. The output is the same dataframe with an extra column containing integer encoded cluster labels. Below is an example based on the Iris dataset:

from anti_clustering import ExactClusterEditingAntiClustering
from sklearn import datasets
import pandas as pd

iris_data = datasets.load_iris(as_frame=True)
iris_df = pd.DataFrame(data=iris_data.data, columns=iris_data.feature_names)

algorithm = ExactClusterEditingAntiClustering()

df = algorithm.run(
    df=iris_df,
    numerical_columns=list(iris_df.columns),
    categorical_columns=None,
    num_groups=2,
    destination_column='Cluster'
)

Contributions

If you have any suggestions or have found a bug, feel free to open issues. If you have implemented a new algorithm or know how to tweak the existing ones; PRs are very appreciated.

License

This library is licensed under the Apache 2.0 license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anti-clustering-0.1.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

anti_clustering-0.1.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file anti-clustering-0.1.0.tar.gz.

File metadata

  • Download URL: anti-clustering-0.1.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0b2 CPython/3.9.13 Linux/5.13.0-1031-azure

File hashes

Hashes for anti-clustering-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d2b60c372e8cd47bc3751a477ce5f08a219a22c2115f10bbdbdab6cd9a97d5e8
MD5 203b00fe342b9a11df2ad0363ef07c17
BLAKE2b-256 767d4c6f8bfe05cfaefdd35cd88cbd7dc44c4760707060aeaac085110c3cfa8a

See more details on using hashes here.

File details

Details for the file anti_clustering-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: anti_clustering-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0b2 CPython/3.9.13 Linux/5.13.0-1031-azure

File hashes

Hashes for anti_clustering-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3c90024d547a7ecdb71e9488e5dfa56d3ab093de21987fb56482d3830a1d43d
MD5 8a66f46ed9f5fc287ae348631e164f8e
BLAKE2b-256 4a74ce9693b6270b25a12b3b593fea922ad537bde669d43e3d855162769d64b7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page