This Python script implements a genetic algorithm for clustering data. The algorithm optimizes the cluster assignments of data points using a genetic approach, aiming to improve the silhouette score. The silhouette score is a measure of how well-defined the clusters are in the data.
Project description
Genetic Clustering Algorithm
This Python script implements a genetic algorithm for clustering data. The algorithm optimizes the cluster assignments of data points using a genetic approach, aiming to improve the silhouette score. The silhouette score is a measure of how well-defined the clusters are in the data.
Table of Contents
Getting Started
Prerequisites
- Python 3
- Required libraries: numpy, pandas, scikit-learn, matplotlib
Installation
- Clone the repository:
https://github.com/parvvaresh/cluster_ga
cd cluster_ga
- Install the required dependencies:
pip install -r requirements.txt
Usage
Run the genetic_clustering.py script to execute the genetic clustering algorithm on the provided dataset. Make sure to update the script with your dataset or use the default Iris dataset.
python3 test_iris.py
Algorithm Overview
The genetic clustering algorithm consists of the following components:
Genetic Class
Defines the genetic operations such as mutation, generation, and fitness calculation.
Cluster Class
Manages the clustering process, including the initialization of populations, evolution, and convergence.
Main Script
Utilizes the genetic and clustering classes to run the algorithm on a given dataset.
Parameters
size_population: Number of individuals in the population.goal: The desired fitness score to achieve.repeat: Number of generations to run the algorithm.is_mutation: Boolean flag to enable or disable mutation.
Results
The script outputs the progress of the algorithm, including the generation number and the fitness score achieved. Additionally, a plot of the fitness scores over generations is displayed at the end of the execution.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Acknowledgments
- This implementation is inspired by genetic algorithms and clustering techniques.
- Special thanks to the scikit-learn library for providing the silhouette score metric.
Project details
Release history Release notifications | RSS feed
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 cluster_ga-0.1.tar.gz.
File metadata
- Download URL: cluster_ga-0.1.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4b7558561694203894dc02b48b202e6177469355d5fc171a01a47ad13397f64
|
|
| MD5 |
f5ea20081bd9f305db613f7977b1d89f
|
|
| BLAKE2b-256 |
2da4b4fdcbd8724a2ac8d54710b1ae136435a4c865a6d748c1de843446de5d74
|
File details
Details for the file cluster_ga-0.1-py3-none-any.whl.
File metadata
- Download URL: cluster_ga-0.1-py3-none-any.whl
- Upload date:
- Size: 2.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7800bd12e9c3190a476b0bcb36482ee1d186ae154a4a9c760db15885111153e1
|
|
| MD5 |
014e33e8aa2306ed6f4668d92a88aaeb
|
|
| BLAKE2b-256 |
317ebac7cc36aee3f014863782971273b8d9159cf9053451c48471be17d12817
|