To keep my promise, here is all the code you will need to get your first genetic algorithm working with the EasyGA package.

pip3 install EasyGA

Run the code below in a python file anywhere on your computer.

import EasyGA

## Create the Genetic algorithm
ga = EasyGA.GA()

## Evolve the genetic algorithm until termination has been reached
ga.evolve()

## Print out the current generation and the population
ga.print_generation()
ga.print_population()

Output:

Current Generation      : 15
Current population:
Chromosome - 0 [7][4][4][5][3][5][5][8][3][7] / Fitness = 3
Chromosome - 1 [7][4][4][5][3][5][5][8][3][7] / Fitness = 3
Chromosome - 2 [7][4][4][5][3][5][5][8][3][7] / Fitness = 3
Chromosome - 3 [7][4][4][5][3][5][5][8][3][7] / Fitness = 3
Chromosome - 4 [7][2][4][5][3][5][5][8][3][7] / Fitness = 3
Chromosome - 5 [7][2][4][5][3][5][5][8][3][7] / Fitness = 3
Chromosome - 6 [5][8][8][6][10][10][5][7][2][7] / Fitness = 2
Chromosome - 7 [5][8][8][6][10][10][5][7][2][7] / Fitness = 2
Chromosome - 8 [5][8][8][6][10][10][5][7][2][7] / Fitness = 2
Chromosome - 9 [7][2][8][10][3][5][5][8][1][7] / Fitness = 2

Congratulations, you have done some python import magic and created a genetic algorithm to solve the problem of getting all 5’s in the chromosome. You can basically call yourself an A.I data scientist. Now let’s unpack everything that happened and how we can change this beast.

#python #ai

EasyGA: Genetic Algorithms Made Easy. Genetic algorithm in 5 lines of Python
3.60 GEEK