# FuzzyCMeans: A Fuzzy C-Means Clustering Extension for Scikit-Learn
![Python](https://img.shields.io/badge/python-3.9%2B-blue.svg)
![License](https://img.shields.io/badge/license-MIT-green.svg)
## Overview
`FuzzyCMeans` is a Scikit-Learn-compatible implementation of the **Fuzzy C-Means** clustering algorithm. This algorithm extends traditional clustering techniques by allowing data points to belong to multiple clusters with varying degrees of membership, making it ideal for datasets with overlapping or ambiguous cluster boundaries.
This package is designed to seamlessly integrate with the Scikit-Learn ecosystem, offering a familiar API and compatibility with pipelines, transformers, and other utilities.
---
## Features
- **Fuzzy Membership**: Assigns data points to clusters with degrees of membership, offering more flexibility than hard clustering methods.
- **Scikit-Learn Compatible**: Implements the `BaseEstimator` and `ClusterMixin` interfaces for easy integration.
- **K-Means++ Initialization**: Utilizes the robust K-Means++ algorithm for initializing cluster centers.
- **Customizable Parameters**: Adjust the number of clusters, fuzziness coefficient, convergence tolerance, and maximum iterations.
- **Reproducibility**: Supports setting a random seed for reproducible results.
---
## Installation
### Using pip
```bash
pip install scikit-fuzzy-c-means
```
### Manual Installation
Clone the repository and install dependencies:
```bash
git clone https://github.com/your-repo/fuzzy-c-means
cd fuzzy-c-means
pip install -r requirements.txt
```
---
## Quick Start
### Import and Initialize
```python
from fuzzy_c_means import FuzzyCMeans
import numpy as np
# Sample dataset
X = np.array([[1.0, 2.0], [1.5, 1.8], [5.0, 8.0], [8.0, 8.0], [1.0, 0.6], [9.0, 11.0]])
# Initialize the FuzzyCMeans model
fcm = FuzzyCMeans(n_clusters=2, m=2, max_iter=150, tol=1e-4, random_state=42)
```
### Fit and Predict
```python
# Fit the model to the data
fcm.fit(X)
# Predict cluster labels
labels = fcm.predict(X)
# View cluster centers
print("Cluster Centers:")
print(fcm.cluster_centers_)
```
---
## Parameters
| Parameter | Type | Description | Default |
|---------------|--------|---------------------------------------------------------------------------------------------|-----------|
| `n_clusters` | `int` | Number of clusters to find. | `3` |
| `m` | `float`| Fuzziness coefficient. Larger values lead to fuzzier clusters (`m > 1`). | `2` |
| `max_iter` | `int` | Maximum number of iterations for the algorithm to converge. | `150` |
| `tol` | `float`| Convergence tolerance. Stops iteration when changes are smaller than this value. | `1e-4` |
| `random_state`| `int` | Random seed for reproducibility. | `None` |
---
## Methods
### `fit(X, y=None)`
Fits the Fuzzy C-Means model to the input data `X`.
### `predict(X)`
Predicts hard cluster labels for the input data `X` based on fuzzy memberships.
### `fit_predict(X, y=None)`
Fits the model to `X` and returns the predicted hard cluster labels.
### `cluster_centers_`
Returns the cluster centers after fitting the model.
---
## Use Cases
1. **Image Segmentation**: Separate regions of an image into clusters based on color, texture, or intensity.
2. **Market Segmentation**: Group customers into fuzzy clusters based on purchasing behavior and demographics.
3. **Anomaly Detection**: Identify data points with low membership to any cluster as potential outliers.
4. **Genomics**: Analyze genetic data to classify genes or species with ambiguous relationships.
---
## Advantages
- **Soft Clustering**: Unlike K-Means, Fuzzy C-Means allows for nuanced assignments of data points to multiple clusters.
- **Customizable Fuzziness**: Control the degree of fuzziness with the `m` parameter.
- **Robust Initialization**: Reduces the impact of poor initializations with K-Means++.
---
## Requirements
- Python 3.9 or higher
- NumPy
- SciPy
- Scikit-Learn
Install dependencies with:
```bash
pip install -r requirements.txt
```
---
## Contributing
Contributions are welcome! Feel free to submit a pull request or report issues in the [GitHub repository](https://github.com/your-repo/fuzzy-c-means).
---
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
---
## Keywords
- Fuzzy C-Means
- Soft Clustering
- Machine Learning
- Scikit-Learn
- Python
- Clustering Algorithm
- Data Science
---
## References
- Bezdek, J.C. "Pattern Recognition with Fuzzy Objective Function Algorithms." Springer, 1981.
- [Scikit-Learn Documentation](https://scikit-learn.org/stable/)
- [K-Means++ Paper](https://theory.stanford.edu/~sergei/papers/kMeansPP-soda.pdf)
---
## Acknowledgments
This implementation is inspired by the principles of fuzzy clustering and integrates seamlessly with Scikit-Learn for ease of use in real-world machine learning pipelines.
Raw data
{
"_id": null,
"home_page": "https://github.com/sageteamorg/scikit-fuzzy-c-means",
"name": "scikit-fuzzy-c-means",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Sepehr Akbarzadeh",
"author_email": "sa.goldeneagle@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/b0/c8/8936c2af0c077a322be186c7d7370ac91b6d3952bfd462eea06a64b28450/scikit_fuzzy_c_means-0.1.3.tar.gz",
"platform": null,
"description": "# FuzzyCMeans: A Fuzzy C-Means Clustering Extension for Scikit-Learn\n\n![Python](https://img.shields.io/badge/python-3.9%2B-blue.svg)\n![License](https://img.shields.io/badge/license-MIT-green.svg)\n\n## Overview\n\n`FuzzyCMeans` is a Scikit-Learn-compatible implementation of the **Fuzzy C-Means** clustering algorithm. This algorithm extends traditional clustering techniques by allowing data points to belong to multiple clusters with varying degrees of membership, making it ideal for datasets with overlapping or ambiguous cluster boundaries.\n\nThis package is designed to seamlessly integrate with the Scikit-Learn ecosystem, offering a familiar API and compatibility with pipelines, transformers, and other utilities.\n\n---\n\n## Features\n\n- **Fuzzy Membership**: Assigns data points to clusters with degrees of membership, offering more flexibility than hard clustering methods.\n- **Scikit-Learn Compatible**: Implements the `BaseEstimator` and `ClusterMixin` interfaces for easy integration.\n- **K-Means++ Initialization**: Utilizes the robust K-Means++ algorithm for initializing cluster centers.\n- **Customizable Parameters**: Adjust the number of clusters, fuzziness coefficient, convergence tolerance, and maximum iterations.\n- **Reproducibility**: Supports setting a random seed for reproducible results.\n\n---\n\n## Installation\n\n### Using pip\n```bash\npip install scikit-fuzzy-c-means\n```\n\n### Manual Installation\nClone the repository and install dependencies:\n```bash\ngit clone https://github.com/your-repo/fuzzy-c-means\ncd fuzzy-c-means\npip install -r requirements.txt\n```\n\n---\n\n## Quick Start\n\n### Import and Initialize\n```python\nfrom fuzzy_c_means import FuzzyCMeans\nimport numpy as np\n\n# Sample dataset\nX = np.array([[1.0, 2.0], [1.5, 1.8], [5.0, 8.0], [8.0, 8.0], [1.0, 0.6], [9.0, 11.0]])\n\n# Initialize the FuzzyCMeans model\nfcm = FuzzyCMeans(n_clusters=2, m=2, max_iter=150, tol=1e-4, random_state=42)\n```\n\n### Fit and Predict\n```python\n# Fit the model to the data\nfcm.fit(X)\n\n# Predict cluster labels\nlabels = fcm.predict(X)\n\n# View cluster centers\nprint(\"Cluster Centers:\")\nprint(fcm.cluster_centers_)\n```\n\n---\n\n## Parameters\n\n| Parameter | Type | Description | Default |\n|---------------|--------|---------------------------------------------------------------------------------------------|-----------|\n| `n_clusters` | `int` | Number of clusters to find. | `3` |\n| `m` | `float`| Fuzziness coefficient. Larger values lead to fuzzier clusters (`m > 1`). | `2` |\n| `max_iter` | `int` | Maximum number of iterations for the algorithm to converge. | `150` |\n| `tol` | `float`| Convergence tolerance. Stops iteration when changes are smaller than this value. | `1e-4` |\n| `random_state`| `int` | Random seed for reproducibility. | `None` |\n\n---\n\n## Methods\n\n### `fit(X, y=None)`\nFits the Fuzzy C-Means model to the input data `X`.\n\n### `predict(X)`\nPredicts hard cluster labels for the input data `X` based on fuzzy memberships.\n\n### `fit_predict(X, y=None)`\nFits the model to `X` and returns the predicted hard cluster labels.\n\n### `cluster_centers_`\nReturns the cluster centers after fitting the model.\n\n---\n\n## Use Cases\n\n1. **Image Segmentation**: Separate regions of an image into clusters based on color, texture, or intensity.\n2. **Market Segmentation**: Group customers into fuzzy clusters based on purchasing behavior and demographics.\n3. **Anomaly Detection**: Identify data points with low membership to any cluster as potential outliers.\n4. **Genomics**: Analyze genetic data to classify genes or species with ambiguous relationships.\n\n---\n\n## Advantages\n\n- **Soft Clustering**: Unlike K-Means, Fuzzy C-Means allows for nuanced assignments of data points to multiple clusters.\n- **Customizable Fuzziness**: Control the degree of fuzziness with the `m` parameter.\n- **Robust Initialization**: Reduces the impact of poor initializations with K-Means++.\n\n---\n\n## Requirements\n\n- Python 3.9 or higher\n- NumPy\n- SciPy\n- Scikit-Learn\n\nInstall dependencies with:\n```bash\npip install -r requirements.txt\n```\n\n---\n\n## Contributing\n\nContributions are welcome! Feel free to submit a pull request or report issues in the [GitHub repository](https://github.com/your-repo/fuzzy-c-means).\n\n---\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\n## Keywords\n\n- Fuzzy C-Means\n- Soft Clustering\n- Machine Learning\n- Scikit-Learn\n- Python\n- Clustering Algorithm\n- Data Science\n\n---\n\n## References\n\n- Bezdek, J.C. \"Pattern Recognition with Fuzzy Objective Function Algorithms.\" Springer, 1981.\n- [Scikit-Learn Documentation](https://scikit-learn.org/stable/)\n- [K-Means++ Paper](https://theory.stanford.edu/~sergei/papers/kMeansPP-soda.pdf)\n\n---\n\n## Acknowledgments\n\nThis implementation is inspired by the principles of fuzzy clustering and integrates seamlessly with Scikit-Learn for ease of use in real-world machine learning pipelines.\n",
"bugtrack_url": null,
"license": "BSD 3-Clause License",
"summary": "fuzzy c-means machine learnnig algorithm in scikit-learn style code",
"version": "0.1.3",
"project_urls": {
"Documentation": "https://scikit-fuzzy-c-means.readthedocs.io/en/latest/",
"Homepage": "https://github.com/sageteamorg/scikit-fuzzy-c-means",
"Issues": "https://github.com/sageteamorg/scikit-fuzzy-c-means/issues",
"Repository": "https://github.com/sageteamorg/scikit-fuzzy-c-means"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "bf330265ec09fb11a31e014b7b83992d6004889d5079ea89ca2cc40f8be1e58c",
"md5": "dfc09595870b2e1ff6bec809f48304b7",
"sha256": "f0832e807c687a94c99bc094fcc89903c1b0945c9cfdc345e73d2189caf92d33"
},
"downloads": -1,
"filename": "scikit_fuzzy_c_means-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "dfc09595870b2e1ff6bec809f48304b7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 6848,
"upload_time": "2024-11-19T11:53:27",
"upload_time_iso_8601": "2024-11-19T11:53:27.730277Z",
"url": "https://files.pythonhosted.org/packages/bf/33/0265ec09fb11a31e014b7b83992d6004889d5079ea89ca2cc40f8be1e58c/scikit_fuzzy_c_means-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b0c88936c2af0c077a322be186c7d7370ac91b6d3952bfd462eea06a64b28450",
"md5": "dbc9150d7316031988be64d5849c7a5f",
"sha256": "c86890281606b24344ae04b02bdc722e84bf276423fb5d6c493ea320e8232955"
},
"downloads": -1,
"filename": "scikit_fuzzy_c_means-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "dbc9150d7316031988be64d5849c7a5f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 7502,
"upload_time": "2024-11-19T11:53:29",
"upload_time_iso_8601": "2024-11-19T11:53:29.553239Z",
"url": "https://files.pythonhosted.org/packages/b0/c8/8936c2af0c077a322be186c7d7370ac91b6d3952bfd462eea06a64b28450/scikit_fuzzy_c_means-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-19 11:53:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sageteamorg",
"github_project": "scikit-fuzzy-c-means",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "scikit-fuzzy-c-means"
}