{"id":19528144,"url":"https://github.com/sneaksanddata/anti-clustering","last_synced_at":"2025-04-26T11:32:58.489Z","repository":{"id":40691956,"uuid":"490685637","full_name":"SneaksAndData/anti-clustering","owner":"SneaksAndData","description":"A Python library for anti-clustering algorithms","archived":false,"fork":false,"pushed_at":"2024-08-07T09:50:04.000Z","size":111,"stargazers_count":8,"open_issues_count":6,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-07T11:19:04.302Z","etag":null,"topics":["algorithms","approximation-algorithms","clustering","heuristics","optimisation-algorithms","optimization-algorithms","partitioning-algorithms"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SneaksAndData.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-10T12:25:17.000Z","updated_at":"2024-08-07T09:50:06.000Z","dependencies_parsed_at":"2024-06-12T19:08:17.593Z","dependency_job_id":"5f981575-50aa-4455-8d0b-f19cc16daacc","html_url":"https://github.com/SneaksAndData/anti-clustering","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SneaksAndData%2Fanti-clustering","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SneaksAndData%2Fanti-clustering/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SneaksAndData%2Fanti-clustering/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SneaksAndData%2Fanti-clustering/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SneaksAndData","download_url":"https://codeload.github.com/SneaksAndData/anti-clustering/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224032112,"owners_count":17244373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","approximation-algorithms","clustering","heuristics","optimisation-algorithms","optimization-algorithms","partitioning-algorithms"],"created_at":"2024-11-11T01:17:42.028Z","updated_at":"2024-11-11T01:17:43.234Z","avatar_url":"https://github.com/SneaksAndData.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Anti-clustering\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\nA 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.\nCurrently, a handful of algorithms are implemented in this library:\n* An exact approach using a BIP formulation.\n* An enumerated exchange heuristic.\n* A simulated annealing heuristic.\n\nKeep 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).\n\nThe two former approaches are implemented as described in following paper:\\\n*Papenberg, M., \u0026 Klau, G. W. (2021). Using anticlustering to partition data sets into equivalent parts.\nPsychological Methods, 26(2), 161–174. [DOI](https://doi.org/10.1037/met0000301). [Preprint](https://psyarxiv.com/3razc/)* \\\nThe paper is accompanied by a library for the R programming language: [anticlust](https://github.com/m-Py/anticlust).\n\nDifferently to the [anticlust](https://github.com/m-Py/anticlust) R package, this library currently only have one objective function. \nIn this library the objective will maximise intra-cluster distance: Euclidean distance for numerical columns and Hamming distance for categorical columns.\n\n## Use cases\nWithin software testing, anti-clustering can be used for generating test and control groups in AB-testing.\nExample: You have a webshop with a number of users. The webshop is undergoing active development and you have a new feature coming up. \nThis feature should be tested against as many different users as possible without testing against the entire user-base. \nFor that you can create a maximally diverse subset of the user-base to test against (the A group). \nThe remaining users (B group) will not test this feature. For dividing the user-base you can use the anti-clustering algorithms. \nA 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.\n\nThis is just one use case, probably many more exists.\n\n## Installation\n\nThe anti-clustering package is available on [PyPI](https://pypi.org/project/anti-clustering/). To install it, run the following command:\n\n```bash\npip install anti-clustering\n```\n\nThe package currently supports Python 3.8 and above. \n\n## Usage\nThe 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:\n```python\nfrom anti_clustering import ExactClusterEditingAntiClustering\nfrom sklearn import datasets\nimport pandas as pd\n\niris_data = datasets.load_iris(as_frame=True)\niris_df = pd.DataFrame(data=iris_data.data, columns=iris_data.feature_names)\n\nalgorithm = ExactClusterEditingAntiClustering()\n\ndf = algorithm.run(\n    df=iris_df,\n    numerical_columns=list(iris_df.columns),\n    categorical_columns=None,\n    num_groups=2,\n    destination_column='Cluster'\n)\n```\n\n## Contributions\nIf 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.\n\n## License\nThis library is licensed under the Apache 2.0 license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsneaksanddata%2Fanti-clustering","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsneaksanddata%2Fanti-clustering","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsneaksanddata%2Fanti-clustering/lists"}