A Fair K-Means clustering algorithm with fairness constraints.
Project description
Fair K-Means Clustering
Ensuring demographic fairness in K-Means clustering with AI-driven adjustments.
📌 Overview
Fair K-Means is an enhanced clustering algorithm that incorporates fairness constraints to ensure proportional representation of protected demographic groups in cluster assignments. By leveraging external fairness distributions (via OpenAI API), this approach ensures balanced and unbiased clustering while maintaining clustering quality.
🚀 Installation
Install the package from PyPI:
pip install fair-kmeans-ashwinram
🛠 Usage
Import and apply Fair K-Means Clustering to your dataset:
from fair_kmeans import fair_kmeans
# Apply Fair K-Means on dataset
df, fairness_metrics = fair_kmeans(data, n_clusters=3, protected_col="gender")
# View fairness results
print(fairness_metrics)
🔹 How It Works
1️⃣ Standard K-Means Clustering
- Cluster Assignment: Assigns data points to the nearest centroid.
- Centroid Update: Updates centroids by averaging assigned points.
- Convergence: Stops iterating when centroids stabilize.
2️⃣ Fairness Constraints
- Ensures the distribution of protected attributes (e.g., race, gender) in each cluster aligns with an expected fairness distribution.
- Retrieves fairness constraints dynamically via OpenAI API.
3️⃣ Fairness-Aware Adjustments
- Identifies clusters where demographic representation deviates from expected proportions.
- Reassigns individuals from overrepresented to underrepresented clusters.
- Maintains clustering quality using Silhouette Score as a regulatory measure.
📊 Evaluation Metrics
✔ Fairness Score Computation
Fairness is measured as the absolute deviation between actual and expected demographic proportions:
Fairness Score = | Actual Proportion - Expected Proportion |
A lower fairness score indicates a better-aligned demographic distribution.
✔ Silhouette Score
- Measures how well-separated and cohesive clusters are.
- Used to prevent significant loss of clustering quality during fairness adjustments.
🔹 Key Features
✅ Bias Mitigation: Ensures fair representation across all clusters.
✅ Data-Driven Fairness: Uses external fairness benchmarks instead of assuming equal distribution.
✅ Scalability: Can handle large datasets efficiently.
✅ Interpretability: Outputs fairness scores alongside clustering results.
✅ Regulatory Compliance: Supports fair AI governance (GDPR, Equal Credit Opportunity Act).
📌 Limitations
⚠ Computational Overhead: Fairness adjustments increase processing time.
⚠ Dependency on Fairness Data: External fairness constraints (via OpenAI API) may introduce bias.
⚠ Potential Impact on Clustering Quality: Enforcing fairness may slightly reduce clustering compactness.
💡 Applications
- 📊 Customer Segmentation – Fair clustering in marketing & consumer analytics.
- 📑 Hiring & Recruitment – Ensures diverse and unbiased hiring pools.
- 🏦 Fair Credit Scoring – Reduces demographic bias in financial decision-making.
- 🎓 University Admissions – Promotes equitable student representation.
- 🚔 Predictive Policing – Ensures fairness in criminal justice analytics.
📄 Citation & References
If you use this package in your research, please cite it as:
@article{fairkmeans2024,
title={Fair K-Means Clustering},
author={Ashwin Ram Venkataraman},
journal={PyPI},
year={2024}
}
For further details, refer to:
- Ghadiri et al., 2020 - "Socially Fair K-Means Clustering"
- Bateni et al., 2024 - "Individually Fair K-Means Clustering"
📬 Contact & Support
For questions, issues, or contributions, visit our GitHub repository:
🔗 GitHub Repository
📧 Contact: ashwinram232@gmail.com
Fair K-Means: Where AI Meets Ethical Clustering! 🚀
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fair_kmeans_uchicago-0.1.2.tar.gz.
File metadata
- Download URL: fair_kmeans_uchicago-0.1.2.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2dff52173379404dbd2c698c995e61cc5bbacfe703401ae2d4393ccaa72f514
|
|
| MD5 |
3cb725de4ba4fda847b992b660c124fb
|
|
| BLAKE2b-256 |
f5b4d7a1bc2dafd104888079f0acfabc95d678c17908950deb8ea1375f4772e7
|
File details
Details for the file fair_kmeans_uchicago-0.1.2-py3-none-any.whl.
File metadata
- Download URL: fair_kmeans_uchicago-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32af7935d852258e0bd9a50bcffb97a1aca18dbd0d96eb95ec6dbf2bbb564886
|
|
| MD5 |
b6d384ec9f82385437d38d21a89c2ac2
|
|
| BLAKE2b-256 |
1f3a574643bf8e5c4c2886ed6ef2e6cdf80e8683fa292b4bd145b051bf183362
|