Skip to main content

Genetic Algorithm for Python

Project description

Genetic Machine Learning for Python

GMLP or Genetic Machine Learning for Python, is a user friendly python machine learning package. GMLP is intuitive and can be used for lots of Machine Learning Projects. An Example ->

from gmlp.evolution import Enviroment
from gmlp.mutations import value_encoding_mutation
from gmlp.fitness import Fitness_Function
import matplotlib.pyplot as plt
generations = 1000

hello = [0,1,1,0,1,0,0,0,0,1,1,0,0,1,0,1,0,1,1,0,1,1,0,0,0,1,1,0,1,1,0,0,0,1,1,0,1,1,1,1,0,0,1,0,0,0,0,0,0,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,0,1,1,1,0,0,1,0,0,1,1,0,1,1,0,0,0,1,1,0,0,1,0,0]
e = Enviroment(hello, .9)
population = e.generate_population(len(e.problem), binary=True)

scores = Fitness_Function().calculate_fitness(population, e.problem)
Outputs = []

best = min(scores)
best_ind = scores[scores.index(best)]

score_prog = []
score_prog.append(best_ind)
for generation in range(generations):
    scores = Fitness_Function().calculate_fitness(population, e.problem)
    best = min(scores)
    best_ind = scores[scores.index(best)]
    Output = population[scores.index(best)]

    score_prog.append(best_ind)
    Outputs.append(Output)
    print('Generation:%1d, Best Score:%1s, Output:%2s'%(generation, str(best_ind), str(Output)))
    population = value_encoding_mutation(e.crossover(e.tournament_selection(population, scores, 3), e.problem), .15)
    if min(scores) == 0:
        break
plt.plot(score_prog)
plt.xlabel("Generations")
plt.show()

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

gmlp-0.1a2.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

gmlp-0.1a2-py3-none-any.whl (4.9 kB view hashes)

Uploaded Python 3

Supported by

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