diff --git a/cluster_ga/__pycache__/cluster.cpython-313.pyc b/cluster_ga/__pycache__/cluster.cpython-313.pyc new file mode 100644 index 0000000..b1e50fc Binary files /dev/null and b/cluster_ga/__pycache__/cluster.cpython-313.pyc differ diff --git a/cluster_ga/__pycache__/genetic.cpython-313.pyc b/cluster_ga/__pycache__/genetic.cpython-313.pyc new file mode 100644 index 0000000..ba4a0ea Binary files /dev/null and b/cluster_ga/__pycache__/genetic.cpython-313.pyc differ diff --git a/cluster_ga/cluster.py b/cluster_ga/cluster.py index 4833318..e4861fc 100644 --- a/cluster_ga/cluster.py +++ b/cluster_ga/cluster.py @@ -3,11 +3,11 @@ import matplotlib.pyplot as plt from sklearn import datasets import random -from .genetic import genetic +from .genetic import GeneticClustering -class Cluster: - def __init__(self, X: np.array, y: np.array, size_population: int = 200, goal: float = 0.7, iters: int = 200) -> None: +class cluster: + def __init__(self, X: np.array, y: np.array, size_population: int = 200, goal: float = 0.9, iters: int = 200) -> None: self.X = X self.y = y self.size_population = size_population @@ -23,7 +23,7 @@ def __init__(self, X: np.array, y: np.array, size_population: int = 200, goal: f def fit(self) -> None: for _ in range(self.size_population): chromosome = self._create_random_chromosome() - self.population.append(genetic(chromosome, self.X, self.genom)) + self.population.append(GeneticClustering(chromosome, self.X, self.genom)) self.counter = 1 @@ -51,7 +51,7 @@ def fit(self) -> None: # Apply mutation to the new population for index in range(self.size_population): - self.population[index] = genetic(self.population[index].mutation(), self.X) + self.population[index] = GeneticClustering(self.population[index].mutate(), self.X, self.genom) # Update fitness scores self.fitness.append(self.population[0].fitness_scores) diff --git a/cluster_ga/genetic.py b/cluster_ga/genetic.py index 58c6489..7565f3a 100644 --- a/cluster_ga/genetic.py +++ b/cluster_ga/genetic.py @@ -7,6 +7,7 @@ def __init__(self, chromosome: dict, points: np.array, list_class: list) -> None self.chromosome = chromosome self.points = points self.list_class = list_class + self.fitness_scores = self.get_fitness() def get_fitness(self): labels = np.array(list(self.chromosome.values()))