Skip to content

sherstpasha/thefittest

Repository files navigation

PyPI - Package version Downloads

Profile views

codecov.io

Codacy Badge Code style: black Documentation Status

docs/logos/logo1.png


thefittest is an open-source library designed for the efficient application of classical evolutionary algorithms and their effective modifications in optimization and machine learning. Our project aims to provide performance, accessibility, and ease of use, opening up the world of advanced evolutionary methods to you.

Features of thefittest

Performance
Our library is developed using advanced coding practices and delivers high performance through integration with NumPy, Scipy, Numba, and scikit-learn.
Versatility
thefittest offers a wide range of classical evolutionary algorithms and effective modifications, making it the ideal choice for a variety of optimization and machine learning tasks.
Integration with scikit-learn
Easily integrate machine learning methods from thefittest with scikit-learn tools, creating comprehensive and versatile solutions for evolutionary optimization and model training tasks.

Installation

To install thefittest library, use the following command:

pip install thefittest

Dependencies

thefittest requires:

Usage Example

The following example demonstrates how to use thefittest library with the SHADE optimizer to minimize a custom objective function. This quick start example showcases the main components needed to set up and run an optimization.

from thefittest.optimizers import SHADE

# Define the objective function to minimize
def custom_problem(x):
    return (5 - x[:, 0])**2 + (12 - x[:, 1])**2

# Initialize the SHADE optimizer with custom parameters
optimizer = SHADE(
    fitness_function=custom_problem,
    iters=25,
    pop_size=10,
    left_border=-100,
    right_border=100,
    num_variables=2,
    show_progress_each=10,
    minimization=True,
)

# Run the optimization
optimizer.fit()

# Retrieve and print the best solution found
fittest = optimizer.get_fittest()
print('The fittest individ:', fittest['phenotype'])
print('with fitness', fittest['fitness'])

Machine Learning Example

This example demonstrates how to train a machine learning model on the Iris dataset using thefittest library's MLPEAClassifier with the SHAGA evolutionary optimizer.

from thefittest.optimizers import SHAGA
from thefittest.benchmarks import IrisDataset
from thefittest.classifiers import MLPEAClassifier

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import minmax_scale
from sklearn.metrics import confusion_matrix, f1_score

# Load the Iris dataset
data = IrisDataset()
X = data.get_X()
y = data.get_y()

# Scale features to the [0, 1] range
X_scaled = minmax_scale(X)

# Split the data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.1)

# Initialize the MLPEAClassifier with SHAGA as the optimizer
model = MLPEAClassifier(
    n_iter=500,
    pop_size=500,
    hidden_layers=[5, 5],
    weights_optimizer=SHAGA,
    weights_optimizer_args={"show_progress_each": 10}
)

# Train the model
model.fit(X_train, y_train)

# Make predictions on the test set
predict = model.predict(X_test)

# Evaluate the model
print("confusion_matrix: \n", confusion_matrix(y_test, predict))
print("f1_score: \n", f1_score(y_test, predict, average="macro"))

thefittest contains methods

Benchmarks

Examples

Notebooks on how to use thefittest:

If some notebooks are too big to display, you can use NBviewer.

Kaggle Notebooks

Articles

Publications where thefittest has been used:

  • Thefittest: evolutionary machine learning in Python, January 2024, ITM Web of Conferences 59. DOI: 10.1051/itmconf/20245902020. Licensed under CC BY 4.0. Authored by Pavel Sherstnev. Available at: https://doi.org/10.1051/itmconf/20245902020

Awards and Presentations

  • 1st place, Samsung Innovation Campus (IT Academy), Artificial Intelligence track, October 2024. Read more;
  • Best PhD Student Paper at the 12th International Workshop on Mathematical Models and their Applications (IWMMA'2023) for the paper "Thefittest: Evolutionary Machine Learning in Python" by Pavel Sherstnev;
  • Tutorial Presenter at the 13th International Workshop on Mathematical Models and their Applications (IWMMA'2024) with the tutorial titled "Thefittest Library: Evolutionary Algorithms and Automation of Machine Learning Models Design in Python".