Skip to main content

mloptimizer is a Python library for optimizing hyperparameters of machine learning algorithms using genetic algorithms.

Project description

mloptimizer_banner

Documentation Status PyPI version PyPI pyversions Tests Coverage Status Shield: Buy me a coffee

mloptimizer is a Python library for optimizing hyperparameters of machine learning algorithms using genetic algorithms. With mloptimizer, you can find the optimal set of hyperparameters for a given machine learning model and dataset, which can significantly improve the performance of the model. The library supports several popular machine learning algorithms, including decision trees, random forests, and gradient boosting classifiers. The genetic algorithm used in mloptimizer provides an efficient and flexible approach to search for the optimal hyperparameters in a large search space.

Features

  • Easy to use
  • DEAP-based genetic algorithm ready to use with several machine learning algorithms
  • Adaptable to use with any machine learning algorithm that complies with the Scikit-Learn API
  • Default hyperparameter ranges
  • Default score functions for evaluating the performance of the model
  • Reproducibility of results

Advanced Features

  • Extensible with more machine learning algorithms that comply with the Scikit-Learn API
  • Customizable hyperparameter ranges
  • Customizable score functions
  • Optional mlflow compatibility for tracking the optimization process

Installation

It is recommended to create a virtual environment using the venv package. To learn more about how to use venv, check out the official Python documentation at https://docs.python.org/3/library/venv.html.

# Create the virtual environment
python -m venv myenv
# Activate the virtual environment
source myenv/bin/activate

To install mloptimizer, run:

pip install mloptimizer

You can get more information about the package installation at https://pypi.org/project/mloptimizer/.

Quickstart

Here's a simple example of how to optimize hyperparameters in a decision tree classifier using the iris dataset:

from mloptimizer.interfaces import GeneticSearch, HyperparameterSpaceBuilder
from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import load_iris

# 1) Load the dataset and get the features and target
X, y = load_iris(return_X_y=True)

# 2) Define the hyperparameter space (a default space is provided for some algorithms)
hyperparameter_space = HyperparameterSpaceBuilder.get_default_space(DecisionTreeClassifier)

# 3) Create the optimizer and optimize the classifier
# - 10 generations starting with a population of 10 individuals, other parameters are set to default

opt = GeneticSearch(estimator_class=DecisionTreeClassifier,
                    hyperparam_space=hyperparameter_space,
                    genetic_params_dict={"generations": 5, "population_size": 5}
                    )

# 4) Optimize the classifier, the optimization returns the best estimator found in the optimization process
opt.fit(X, y)

print(opt.best_estimator_)

Other algorithms can be used, such as RandomForestClassifier or XGBClassifier which have a default hyperparameter space defined in the library. Even if the algorithm is not included in the default hyperparameter space, you can define your own hyperparameter space following the documentation.

More details in the documentation.

Examples

Examples can be found in examples on readthedocs.io.

Dependencies

The following dependencies are used in mloptimizer:

  • Deap - Genetic Algorithms
  • XGBoost - Gradient boosting classifier
  • Scikit-Learn - Machine learning algorithms and utilities

Optional:

  • Keras - Deep learning library
  • mlflow - Tracking the optimization process

Documentation

The documentation for mloptimizer can be found in the project's wiki with examples, classes and methods reference.

Authors

  • Antonio Caparrini - Author - caparrini
  • Javier Arroyo Gallardo - Author - javiag

Analytics

Alt

License

This project is licensed under the MIT License.

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

mloptimizer-0.9.0.3.tar.gz (49.2 kB view details)

Uploaded Source

Built Distribution

mloptimizer-0.9.0.3-py3-none-any.whl (66.0 kB view details)

Uploaded Python 3

File details

Details for the file mloptimizer-0.9.0.3.tar.gz.

File metadata

  • Download URL: mloptimizer-0.9.0.3.tar.gz
  • Upload date:
  • Size: 49.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for mloptimizer-0.9.0.3.tar.gz
Algorithm Hash digest
SHA256 84e27355a8792f4b98639b4a345afabeaedd908f14f8541082a6e79bc8cae530
MD5 4837a5f656da98ef92f45e52984e3fee
BLAKE2b-256 68be4bd8cfa19788a521ef3e63fc2a02767ec697e86f69946c2bf432acfd8bf8

See more details on using hashes here.

File details

Details for the file mloptimizer-0.9.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for mloptimizer-0.9.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8a9ce579e909615640deef8ab3a9f1dd0993ca950815374fe382866351638b64
MD5 cc65dbe43032f6fee1d3df32e1ff7a5c
BLAKE2b-256 07b17d85cbf72401c20ec651aac178fdb8f41fc9905599fe86a150d9b3830265

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