Skip to main content

GeneticPy is an optimizer that uses a genetic algorithm to quickly search through custom parameter spaces for optimal solutions.

Project description

GeneticPy

Build Status codecov PyPI version PyPI pyversions Downloads

GeneticPy is an optimizer that uses a genetic algorithm to quickly search through custom parameter spaces for optimal solutions.

Installation

GeneticPy requires Python 3.6+

pip install geneticpy

Optimize Example:

A brief example to get you started is included below:

import geneticpy

def loss_function(params):
  if params['type'] == 'add':
    return params['x'] + params['y']
  elif params['type'] == 'multiply':
    return params['x'] * params['y']

param_space = {'type': geneticpy.ChoiceDistribution(choice_list=['add', 'multiply']),
               'x': geneticpy.UniformDistribution(low=5, high=10, q=1),
               'y': geneticpy.GaussianDistribution(mean=0, standard_deviation=1)}

results = geneticpy.optimize(loss_function, param_space, size=200, generation_count=500, verbose=True)
best_params = results['top_params']
loss = results['top_score']
total_time = results['total_time']

GeneticSearchCV Example:

You can use the GeneticSearchCV class as a drop-in replacement for Scikit-Learn's GridSearchCV. This allows for faster and more complete optimization of your hyperparameters when using Scikit-Learn estimators and/or pipelines.

from sklearn import datasets
from sklearn.decomposition import PCA
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline

from geneticpy import GeneticSearchCV, ChoiceDistribution, LogNormalDistribution, UniformDistribution


# Define a pipeline to search for the best combination of PCA truncation
# and classifier regularization.
pca = PCA()
# set the tolerance to a large value to make the example faster
logistic = LogisticRegression(max_iter=10000, tol=0.1, solver='saga')
pipe = Pipeline(steps=[('pca', pca), ('logistic', logistic)])

X_digits, y_digits = datasets.load_digits(return_X_y=True)

# Parameters of pipelines can be set using ‘__’ separated parameter names:
param_grid = {
    'pca__n_components': UniformDistribution(low=5, high=64, q=1),
    'logistic__C': LogNormalDistribution(mean=1, sigma=0.5, low=0.001, high=2),
    'logistic__penalty': ChoiceDistribution(choice_list=['l1', 'l2'])
}
search = GeneticSearchCV(pipe, param_grid)
search.fit(X_digits, y_digits)
print("Best parameter (CV score=%0.3f):" % search.best_score_)
print(search.best_params_)

PyPi Project

https://pypi-hypernode.com/project/geneticpy/

Contact

Please feel free to email me at brandonschabell@gmail.com with any questions or feedback.

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

geneticpy-1.2.3.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

geneticpy-1.2.3-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file geneticpy-1.2.3.tar.gz.

File metadata

  • Download URL: geneticpy-1.2.3.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

File hashes

Hashes for geneticpy-1.2.3.tar.gz
Algorithm Hash digest
SHA256 dd1029f67ab0472128b2ef26d19528a55ff339f31c62b36ac393b87cd36a09a5
MD5 c1b73d780101cf6e626814a091314630
BLAKE2b-256 98c07d5e3e63f7b3498c7c2ef4d81b9338f6ba8b60d049dbd856675356d17d78

See more details on using hashes here.

File details

Details for the file geneticpy-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: geneticpy-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12

File hashes

Hashes for geneticpy-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e8a6732389022fda30372762aa3e419ae5e61954213984fdb49d720032699756
MD5 908ef5ada0546db7bad1d23ff4d1a60a
BLAKE2b-256 20eb32ee54b11d699b157247c7b5f2054e3907cfc9a04a9d1410e4203c6b6665

See more details on using hashes here.

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