Giter Site home page Giter Site logo

genepy's Introduction

Genepy - A simple genetic programming library

license

Genepy is a high-level library implementing a genetic programming algorithm using a tree representation for individuals. It is compatible with Python 2.7 and all the following versions and uses only the standard library (no dependencies).

It can be used to solve linear and nonlinear regression problems and is usable through a simple interface:

  • A fit function that takes as inputs the training examples, target values and the number of iterations
  • A predict function that takes as parameter an input for prediction

An example of usage can be found in the example.py script. This example requires to have the libraries numpy and matplotlib installed.

Installation

The package can be installed simply using Pypi:

pip install genepy

Usage

To use it, you need to give the algorithm:

  • A fitness function that takes as parameters:
    • An instance of the class Tree
    • The training examples: array-like object of shape [n_samples, n_features]
    • The target values: array-like object of shape [n_samples]
  • The function set that can be used in the tree

Basic example:

from operator import add, sub, mul
from genepy.core import EvolutionaryAlgorithm

# Load your dataset
train_features, train_targets = ...
test_features, test_targets   = ...

# Define a fitness function
def compute_fitness(tree, features, targets):
    ...
    return fitness

# Define the parameters of the algorithm
parameters = {
  'min_depth':        2,
  'max_depth':        5,
  'nb_trees':         50,
  'max_const':        100,
  'func_ratio':       0.5,
  'var_ratio':        0.5,
  'crossover_prob':   0.8,
  'mutation_prob':    0.2,
  'iterations':       80,
  'functions':        [add,sub,mul],
  'fitness_function': compute_fitness
}

# Create object and train algorithm
ea = EvolutionaryAlgorithm(**parameters)
ea.fit(train_features, train_targets)

# Make a prediction
predicted = ea.predict(test_features[0])

genepy's People

Contributors

amstuta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.