<p align="center">
<img style="max-width:100%;" src="https://thieu1995.github.io/post/2023-08/MetaCluster-01.png" alt="MetaCluster"/>
</p>
---
[![GitHub release](https://img.shields.io/badge/release-1.2.0-yellow.svg)](https://github.com/thieu1995/metacluster/releases)
[![Wheel](https://img.shields.io/pypi/wheel/gensim.svg)](https://pypi.python.org/pypi/metacluster)
[![PyPI version](https://badge.fury.io/py/metacluster.svg)](https://badge.fury.io/py/metacluster)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/metacluster.svg)
![PyPI - Status](https://img.shields.io/pypi/status/metacluster.svg)
[![Downloads](https://static.pepy.tech/badge/MetaCluster)](https://pepy.tech/project/MetaCluster)
[![Tests & Publishes to PyPI](https://github.com/thieu1995/metacluster/actions/workflows/publish-package.yaml/badge.svg)](https://github.com/thieu1995/metacluster/actions/workflows/publish-package.yaml)
![GitHub Release Date](https://img.shields.io/github/release-date/thieu1995/metacluster.svg)
[![Documentation Status](https://readthedocs.org/projects/metacluster/badge/?version=latest)](https://metacluster.readthedocs.io/en/latest/?badge=latest)
[![Chat](https://img.shields.io/badge/Chat-on%20Telegram-blue)](https://t.me/+fRVCJGuGJg1mNDg1)
![GitHub contributors](https://img.shields.io/github/contributors/thieu1995/metacluster.svg)
[![GitTutorial](https://img.shields.io/badge/PR-Welcome-%23FF8300.svg?)](https://git-scm.com/book/en/v2/GitHub-Contributing-to-a-Project)
[![DOI](https://zenodo.org/badge/670197315.svg)](https://zenodo.org/badge/latestdoi/670197315)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
MetaCluster is the largest open-source nature-inspired optimization (Metaheuristic Algorithms) library for
clustering problem in Python
* **Free software:** GNU General Public License (GPL) V3 license
* **Provided 3 classes: `MetaCluster`, `MhaKCentersClustering`, and `MhaKMeansTuner`**
* **Total nature-inspired metaheuristic optimizers (Metaheuristic Algorithms)**: > 200 optimizers
* **Total objective functions (as fitness)**: > 40 objectives
* **Total supported datasets**: 48 datasets from Scikit learn, UCI, ELKI, KEEL...
* **Total performance metrics**: > 40 metrics
* **Total different way of detecting the K value**: >= 10 methods
* **Documentation:** https://metacluster.readthedocs.io/en/latest/
* **Python versions:** >= 3.7.x
* **Dependencies:** numpy, scipy, scikit-learn, pandas, mealpy, permetrics, plotly, kaleido
# Installation
* Install the [current PyPI release](https://pypi.python.org/pypi/metacluster):
```sh
$ pip install metacluster==1.2.0
```
* Install directly from source code
```sh
$ git clone https://github.com/thieu1995/metacluster.git
$ cd metacluster
$ python setup.py install
```
* In case, you want to install the development version from Github:
```sh
$ pip install git+https://github.com/thieu1995/permetrics
```
After installation, you can import MetaCluster as any other Python module:
```sh
$ python
>>> import metacluster
>>> metacluster.__version__
```
### Examples
Let's go through some examples.
#### 1. First, load dataset. You can use the available datasets from MetaCluster:
```python
# Load available dataset from MetaCluster
from metacluster import get_dataset
# Try unknown data
get_dataset("unknown")
# Enter: 1 -> This wil list all of avaialble dataset
data = get_dataset("Arrhythmia")
```
* Or you can load your own dataset
```python
import pandas as pd
from metacluster import Data
# load X and y
# NOTE MetaCluster accepts numpy arrays only, hence use the .values attribute
dataset = pd.read_csv('examples/dataset.csv', index_col=0).values
X, y = dataset[:, 0:-1], dataset[:, -1]
data = Data(X, y, name="my-dataset")
```
#### 2. Next, scale your features
**You should confirm that your dataset is scaled and normalized**
```python
# MinMaxScaler
data.X, scaler = data.scale(data.X, method="MinMaxScaler", feature_range=(0, 1))
# StandardScaler
data.X, scaler = data.scale(data.X, method="StandardScaler")
# MaxAbsScaler
data.X, scaler = data.scale(data.X, method="MaxAbsScaler")
# RobustScaler
data.X, scaler = data.scale(data.X, method="RobustScaler")
# Normalizer
data.X, scaler = data.scale(data.X, method="Normalizer", norm="l2") # "l1" or "l2" or "max"
```
#### 3. Next, select Metaheuristic Algorithm, Its parameters, list of objectives, and list of performance metrics
```python
list_optimizer = ["BaseFBIO", "OriginalGWO", "OriginalSMA"]
list_paras = [
{"name": "FBIO", "epoch": 10, "pop_size": 30},
{"name": "GWO", "epoch": 10, "pop_size": 30},
{"name": "SMA", "epoch": 10, "pop_size": 30}
]
list_obj = ["SI", "RSI"]
list_metric = ["BHI", "DBI", "DI", "CHI", "SSEI", "NMIS", "HS", "CS", "VMS", "HGS"]
```
You can check all supported metaheuristic algorithms from: https://github.com/thieu1995/mealpy.
All supported clustering objectives and metrics from: https://github.com/thieu1995/permetrics.
If you don't want to read the documents, you can print out all supported information by:
```python
from metacluster import MetaCluster
# Get all supported methods and print them out
MetaCluster.get_support(name="all")
```
#### 4. Next, create an instance of MetaCluster class and run it.
```python
model = MetaCluster(list_optimizer=list_optimizer, list_paras=list_paras, list_obj=list_obj, n_trials=3, seed=10)
model.execute(data=data, cluster_finder="elbow", list_metric=list_metric, save_path="history", verbose=False)
model.save_boxplots()
model.save_convergences()
```
As you can see, you can define different datasets and using the same model to run it.
Remember to set the name to your dataset, because the folder that hold your results is the name of your dataset.
More examples can be found [here](/examples)
# Support
### Official links (questions, problems)
* Official source code repo: https://github.com/thieu1995/metacluster
* Official document: https://metacluster.readthedocs.io/
* Download releases: https://pypi.org/project/metacluster/
* Issue tracker: https://github.com/thieu1995/metacluster/issues
* Notable changes log: https://github.com/thieu1995/metacluster/blob/master/ChangeLog.md
* Official chat group: https://t.me/+fRVCJGuGJg1mNDg1
* This project also related to our another projects which are optimization and machine learning. Check it here:
* https://github.com/thieu1995/metaheuristics
* https://github.com/thieu1995/mealpy
* https://github.com/thieu1995/mafese
* https://github.com/thieu1995/pfevaluator
* https://github.com/thieu1995/opfunu
* https://github.com/thieu1995/enoppy
* https://github.com/thieu1995/permetrics
* https://github.com/aiir-team
### Citation Request
Please include these citations if you plan to use this library:
```code
@software{van_thieu_nguyen_2023_8220709,
author = {Nguyen Van Thieu},
title = {MetaCluster: An Open-Source Python Library for Metaheuristic-based Clustering Problems},
month = aug,
year = 2023,
publisher = {Zenodo},
doi = {10.5281/zenodo.8214539},
url = {https://github.com/thieu1995/metacluster}
}
@article{van2023mealpy,
title={MEALPY: An open-source library for latest meta-heuristic algorithms in Python},
author={Van Thieu, Nguyen and Mirjalili, Seyedali},
journal={Journal of Systems Architecture},
year={2023},
publisher={Elsevier},
doi={10.1016/j.sysarc.2023.102871}
}
```
### Supported links
```code
1. https://jtemporal.com/kmeans-and-elbow-method/
2. https://medium.com/@masarudheena/4-best-ways-to-find-optimal-number-of-clusters-for-clustering-with-python-code-706199fa957c
3. https://github.com/minddrummer/gap/blob/master/gap/gap.py
4. https://www.tandfonline.com/doi/pdf/10.1080/03610927408827101
5. https://doi.org/10.1016/j.engappai.2018.03.013
6. https://github.com/tirthajyoti/Machine-Learning-with-Python/blob/master/Clustering-Dimensionality-Reduction/Clustering_metrics.ipynb
7. https://elki-project.github.io/
8. https://sci2s.ugr.es/keel/index.php
9. https://archive.ics.uci.edu/datasets
10. https://python-charts.com/distribution/box-plot-plotly/
11. https://plotly.com/python/box-plots/?_ga=2.50659434.2126348639.1688086416-114197406.1688086416#box-plot-styling-mean--standard-deviation
```
Raw data
{
"_id": null,
"home_page": "https://github.com/thieu1995/metacluster",
"name": "metacluster",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "clustering,optimization,k-center clustering,data points,centers,euclidean distance,maximum distance,NP-hard,greedy algorithm,approximation algorithm,covering problem,computational complexity,geometric algorithms,machine learning,pattern recognition,spatial analysis,graph theory,mathematical optimization,dimensionality reduction,mutual information,correlation-based feature selection,Genetic algorithm (GA),Particle swarm optimization (PSO),Ant colony optimization (ACO),Differential evolution (DE),Simulated annealing,Grey wolf optimizer (GWO),Whale Optimization Algorithm (WOA),confusion matrix,recall,precision,accuracy,K-Nearest Neighbors,pearson correlation coefficient (PCC),spearman correlation coefficient (SCC),multi-objectives optimization problems,Stochastic optimization,Global optimization,Convergence analysis,Search space exploration,Local search,Computational intelligence,Robust optimization,Performance analysis,Intelligent optimization,Simulations",
"author": "Thieu",
"author_email": "nguyenthieu2102@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/6c/9f/06720fac21a2d771520d331ddc47bbc3a29945f78c855b98b4d004910681/metacluster-1.2.0.tar.gz",
"platform": null,
"description": "\n<p align=\"center\">\n<img style=\"max-width:100%;\" src=\"https://thieu1995.github.io/post/2023-08/MetaCluster-01.png\" alt=\"MetaCluster\"/>\n</p>\n\n---\n\n[![GitHub release](https://img.shields.io/badge/release-1.2.0-yellow.svg)](https://github.com/thieu1995/metacluster/releases)\n[![Wheel](https://img.shields.io/pypi/wheel/gensim.svg)](https://pypi.python.org/pypi/metacluster) \n[![PyPI version](https://badge.fury.io/py/metacluster.svg)](https://badge.fury.io/py/metacluster)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/metacluster.svg)\n![PyPI - Status](https://img.shields.io/pypi/status/metacluster.svg)\n[![Downloads](https://static.pepy.tech/badge/MetaCluster)](https://pepy.tech/project/MetaCluster)\n[![Tests & Publishes to PyPI](https://github.com/thieu1995/metacluster/actions/workflows/publish-package.yaml/badge.svg)](https://github.com/thieu1995/metacluster/actions/workflows/publish-package.yaml)\n![GitHub Release Date](https://img.shields.io/github/release-date/thieu1995/metacluster.svg)\n[![Documentation Status](https://readthedocs.org/projects/metacluster/badge/?version=latest)](https://metacluster.readthedocs.io/en/latest/?badge=latest)\n[![Chat](https://img.shields.io/badge/Chat-on%20Telegram-blue)](https://t.me/+fRVCJGuGJg1mNDg1)\n![GitHub contributors](https://img.shields.io/github/contributors/thieu1995/metacluster.svg)\n[![GitTutorial](https://img.shields.io/badge/PR-Welcome-%23FF8300.svg?)](https://git-scm.com/book/en/v2/GitHub-Contributing-to-a-Project)\n[![DOI](https://zenodo.org/badge/670197315.svg)](https://zenodo.org/badge/latestdoi/670197315)\n[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n\n\nMetaCluster is the largest open-source nature-inspired optimization (Metaheuristic Algorithms) library for \nclustering problem in Python\n\n* **Free software:** GNU General Public License (GPL) V3 license\n* **Provided 3 classes: `MetaCluster`, `MhaKCentersClustering`, and `MhaKMeansTuner`**\n* **Total nature-inspired metaheuristic optimizers (Metaheuristic Algorithms)**: > 200 optimizers\n* **Total objective functions (as fitness)**: > 40 objectives\n* **Total supported datasets**: 48 datasets from Scikit learn, UCI, ELKI, KEEL...\n* **Total performance metrics**: > 40 metrics\n* **Total different way of detecting the K value**: >= 10 methods\n* **Documentation:** https://metacluster.readthedocs.io/en/latest/\n* **Python versions:** >= 3.7.x\n* **Dependencies:** numpy, scipy, scikit-learn, pandas, mealpy, permetrics, plotly, kaleido\n\n\n# Installation\n\n* Install the [current PyPI release](https://pypi.python.org/pypi/metacluster):\n```sh \n$ pip install metacluster==1.2.0\n```\n\n* Install directly from source code\n```sh \n$ git clone https://github.com/thieu1995/metacluster.git\n$ cd metacluster\n$ python setup.py install\n```\n\n* In case, you want to install the development version from Github:\n```sh \n$ pip install git+https://github.com/thieu1995/permetrics \n```\n\nAfter installation, you can import MetaCluster as any other Python module:\n\n```sh\n$ python\n>>> import metacluster\n>>> metacluster.__version__\n```\n\n### Examples\n\nLet's go through some examples.\n\n#### 1. First, load dataset. You can use the available datasets from MetaCluster:\n\n```python \n# Load available dataset from MetaCluster\nfrom metacluster import get_dataset\n\n# Try unknown data\nget_dataset(\"unknown\")\n# Enter: 1 -> This wil list all of avaialble dataset\n\ndata = get_dataset(\"Arrhythmia\")\n```\n\n* Or you can load your own dataset \n\n```python\nimport pandas as pd\nfrom metacluster import Data\n\n# load X and y\n# NOTE MetaCluster accepts numpy arrays only, hence use the .values attribute\ndataset = pd.read_csv('examples/dataset.csv', index_col=0).values\nX, y = dataset[:, 0:-1], dataset[:, -1]\ndata = Data(X, y, name=\"my-dataset\")\n```\n\n#### 2. Next, scale your features\n\n**You should confirm that your dataset is scaled and normalized**\n\n```python\n# MinMaxScaler \ndata.X, scaler = data.scale(data.X, method=\"MinMaxScaler\", feature_range=(0, 1))\n\n# StandardScaler \ndata.X, scaler = data.scale(data.X, method=\"StandardScaler\")\n\n# MaxAbsScaler \ndata.X, scaler = data.scale(data.X, method=\"MaxAbsScaler\")\n\n# RobustScaler \ndata.X, scaler = data.scale(data.X, method=\"RobustScaler\")\n\n# Normalizer \ndata.X, scaler = data.scale(data.X, method=\"Normalizer\", norm=\"l2\") # \"l1\" or \"l2\" or \"max\"\n```\n\n\n#### 3. Next, select Metaheuristic Algorithm, Its parameters, list of objectives, and list of performance metrics \n\n```python\nlist_optimizer = [\"BaseFBIO\", \"OriginalGWO\", \"OriginalSMA\"]\nlist_paras = [\n {\"name\": \"FBIO\", \"epoch\": 10, \"pop_size\": 30},\n {\"name\": \"GWO\", \"epoch\": 10, \"pop_size\": 30},\n {\"name\": \"SMA\", \"epoch\": 10, \"pop_size\": 30}\n]\nlist_obj = [\"SI\", \"RSI\"]\nlist_metric = [\"BHI\", \"DBI\", \"DI\", \"CHI\", \"SSEI\", \"NMIS\", \"HS\", \"CS\", \"VMS\", \"HGS\"]\n```\n\nYou can check all supported metaheuristic algorithms from: https://github.com/thieu1995/mealpy.\nAll supported clustering objectives and metrics from: https://github.com/thieu1995/permetrics.\n\nIf you don't want to read the documents, you can print out all supported information by:\n\n```python\nfrom metacluster import MetaCluster \n\n# Get all supported methods and print them out\nMetaCluster.get_support(name=\"all\")\n```\n\n\n#### 4. Next, create an instance of MetaCluster class and run it.\n\n```python\nmodel = MetaCluster(list_optimizer=list_optimizer, list_paras=list_paras, list_obj=list_obj, n_trials=3, seed=10)\n\nmodel.execute(data=data, cluster_finder=\"elbow\", list_metric=list_metric, save_path=\"history\", verbose=False)\n\nmodel.save_boxplots()\nmodel.save_convergences()\n```\n\nAs you can see, you can define different datasets and using the same model to run it. \nRemember to set the name to your dataset, because the folder that hold your results is the name of your dataset.\nMore examples can be found [here](/examples)\n\n\n# Support \n\n### Official links (questions, problems)\n\n* Official source code repo: https://github.com/thieu1995/metacluster\n* Official document: https://metacluster.readthedocs.io/\n* Download releases: https://pypi.org/project/metacluster/\n* Issue tracker: https://github.com/thieu1995/metacluster/issues\n* Notable changes log: https://github.com/thieu1995/metacluster/blob/master/ChangeLog.md\n* Official chat group: https://t.me/+fRVCJGuGJg1mNDg1\n\n* This project also related to our another projects which are optimization and machine learning. Check it here:\n * https://github.com/thieu1995/metaheuristics\n * https://github.com/thieu1995/mealpy\n * https://github.com/thieu1995/mafese\n * https://github.com/thieu1995/pfevaluator\n * https://github.com/thieu1995/opfunu\n * https://github.com/thieu1995/enoppy\n * https://github.com/thieu1995/permetrics\n * https://github.com/aiir-team\n\n\n### Citation Request\n\nPlease include these citations if you plan to use this library:\n\n```code \n@software{van_thieu_nguyen_2023_8220709,\n author = {Nguyen Van Thieu},\n title = {MetaCluster: An Open-Source Python Library for Metaheuristic-based Clustering Problems},\n month = aug,\n year = 2023,\n publisher = {Zenodo},\n doi = {10.5281/zenodo.8214539},\n url = {https://github.com/thieu1995/metacluster}\n}\n\n@article{van2023mealpy,\n title={MEALPY: An open-source library for latest meta-heuristic algorithms in Python},\n author={Van Thieu, Nguyen and Mirjalili, Seyedali},\n journal={Journal of Systems Architecture},\n year={2023},\n publisher={Elsevier},\n doi={10.1016/j.sysarc.2023.102871}\n}\n```\n\n### Supported links \n\n```code \n1. https://jtemporal.com/kmeans-and-elbow-method/\n2. https://medium.com/@masarudheena/4-best-ways-to-find-optimal-number-of-clusters-for-clustering-with-python-code-706199fa957c\n3. https://github.com/minddrummer/gap/blob/master/gap/gap.py\n4. https://www.tandfonline.com/doi/pdf/10.1080/03610927408827101\n5. https://doi.org/10.1016/j.engappai.2018.03.013\n6. https://github.com/tirthajyoti/Machine-Learning-with-Python/blob/master/Clustering-Dimensionality-Reduction/Clustering_metrics.ipynb\n7. https://elki-project.github.io/\n8. https://sci2s.ugr.es/keel/index.php\n9. https://archive.ics.uci.edu/datasets\n10. https://python-charts.com/distribution/box-plot-plotly/\n11. https://plotly.com/python/box-plots/?_ga=2.50659434.2126348639.1688086416-114197406.1688086416#box-plot-styling-mean--standard-deviation\n```\n",
"bugtrack_url": null,
"license": "GPLv3",
"summary": "MetaCluster: An Open-Source Python Library for Metaheuristic-based Clustering Problems",
"version": "1.2.0",
"project_urls": {
"Bug Tracker": "https://github.com/thieu1995/metacluster/issues",
"Change Log": "https://github.com/thieu1995/metacluster/blob/master/ChangeLog.md",
"Documentation": "https://metacluster.readthedocs.io/",
"Forum": "https://t.me/+fRVCJGuGJg1mNDg1",
"Homepage": "https://github.com/thieu1995/metacluster",
"Source Code": "https://github.com/thieu1995/metacluster"
},
"split_keywords": [
"clustering",
"optimization",
"k-center clustering",
"data points",
"centers",
"euclidean distance",
"maximum distance",
"np-hard",
"greedy algorithm",
"approximation algorithm",
"covering problem",
"computational complexity",
"geometric algorithms",
"machine learning",
"pattern recognition",
"spatial analysis",
"graph theory",
"mathematical optimization",
"dimensionality reduction",
"mutual information",
"correlation-based feature selection",
"genetic algorithm (ga)",
"particle swarm optimization (pso)",
"ant colony optimization (aco)",
"differential evolution (de)",
"simulated annealing",
"grey wolf optimizer (gwo)",
"whale optimization algorithm (woa)",
"confusion matrix",
"recall",
"precision",
"accuracy",
"k-nearest neighbors",
"pearson correlation coefficient (pcc)",
"spearman correlation coefficient (scc)",
"multi-objectives optimization problems",
"stochastic optimization",
"global optimization",
"convergence analysis",
"search space exploration",
"local search",
"computational intelligence",
"robust optimization",
"performance analysis",
"intelligent optimization",
"simulations"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3f6edc91723c6798da5960ee6c8ee2ef314976ace1d28875d565fc724da51ea6",
"md5": "15b3a9abaa5dd3edf6126703f2bd6593",
"sha256": "4c213d99443331821c1e3d6dc0e0cea6e815bc317c1930351c95a4a3db13cc47"
},
"downloads": -1,
"filename": "metacluster-1.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "15b3a9abaa5dd3edf6126703f2bd6593",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 2661019,
"upload_time": "2023-11-10T16:20:07",
"upload_time_iso_8601": "2023-11-10T16:20:07.153513Z",
"url": "https://files.pythonhosted.org/packages/3f/6e/dc91723c6798da5960ee6c8ee2ef314976ace1d28875d565fc724da51ea6/metacluster-1.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6c9f06720fac21a2d771520d331ddc47bbc3a29945f78c855b98b4d004910681",
"md5": "fe7dd8a227da6e4dba5a6060128db0be",
"sha256": "66193a59efca7964066915dd8e070a371315ecf3173f4f39ba3e3f0881065830"
},
"downloads": -1,
"filename": "metacluster-1.2.0.tar.gz",
"has_sig": false,
"md5_digest": "fe7dd8a227da6e4dba5a6060128db0be",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 2580253,
"upload_time": "2023-11-10T16:20:09",
"upload_time_iso_8601": "2023-11-10T16:20:09.155930Z",
"url": "https://files.pythonhosted.org/packages/6c/9f/06720fac21a2d771520d331ddc47bbc3a29945f78c855b98b4d004910681/metacluster-1.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-10 16:20:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "thieu1995",
"github_project": "metacluster",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "metacluster"
}