Skip to main content

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

Installation

  1. Install the required dependencies:
pip install cluster_ga

Usage

from sklearn import datasets
import numpy as np
import pandas as pd
from cluster_ga.cluster import cluster

# this is a for test

iris = datasets.load_iris()
iris_df = pd.DataFrame(iris.data, columns=iris.feature_names)
x = np.array(iris_df[["petal length (cm)", "petal width (cm)"]])
y = iris.target

# Instantiate and fit the model
model = cluster(x, y, 500, 0.9,150) 
model.fit()


# show fitness plot
model.show_plot()

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.

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.

result

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cluster_ga-0.2.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cluster_ga-0.2-py3-none-any.whl (2.2 kB view details)

Uploaded Python 3

File details

Details for the file cluster_ga-0.2.tar.gz.

File metadata

  • Download URL: cluster_ga-0.2.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

Hashes for cluster_ga-0.2.tar.gz
Algorithm Hash digest
SHA256 4c9c697596164c6cb7804f59ab7038e588fa6e9da22f6a0701bf9b4591b0096a
MD5 d0a2acfcf30f71f0c95fa0bc90e63d59
BLAKE2b-256 c08e26f449e38a61905030c840d37f096b5e13fdacfb2ce38de91eeb00b9ebfa

See more details on using hashes here.

File details

Details for the file cluster_ga-0.2-py3-none-any.whl.

File metadata

  • Download URL: cluster_ga-0.2-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

Hashes for cluster_ga-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9f71d16e3b23270029a45bfe4201897840d1200278c6d30c7cf492db44c55c76
MD5 e894c88f8945de8b75c752083e7eccf3
BLAKE2b-256 d88667ac2c5ca334781835fc422ad5c4d4b7ce143667cb3f4c5021ce84e5621a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page