Package: mloptimizer
mloptimizeris 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.FeaturesEasy to useDEAP-based genetic algorithm ready to use with several machine learning algorithmsDefault hyperparameter rangesDefault score functions for evaluating the performance of the modelReproducibility of resultsAdvanced FeaturesExtensible with more machine learning algorithms that comply with the Scikit-Learn APICustomizable hyperparameter rangesCustomizable score functionsInstallationIt is recommended to create a virtual environment using thevenvpackage.
To learn more about how to usevenv,
check out the official Python documentation athttps://docs.python.org/3/library/venv.html.# Create the virtual environmentpython-mvenvmyenv# Activate the virtual environmentsourcemyenv/bin/activateTo installmloptimizer, run:pipinstallmloptimizerYou can get more information about the package installation athttps://pypi.org/project/mloptimizer/.QuickstartHere's a simple example of how to optimize hyperparameters in a decision tree classifier using the iris dataset:frommloptimizer.genoptimizerimportTreeOptimizerfromsklearn.datasetsimportload_irisX,y=load_iris(return_X_y=True)#opt=TreeOptimizer(X,y,"Optimizer")clf=opt.optimize_clf(10,10)The last line of code will create a directory in the current folder with a name likeYYYYMMDD_nnnnnnnnnn_TreeOptimizer.
This folder contains the results of the optimization,
including the best estimator found and the log fileopt.loginforming with all the steps,
the best estimator and the result of the optimization.A structure like this will be created:├── checkpoints
│   ├── cp_gen_0.pkl
│   └── cp_gen_1.pkl
├── graphics
│   ├── logbook.html
│   └── search_space.html
├── opt.log
├── progress
│   ├── Generation_0.csv
│   └── Generation_1.csv
└── results
    ├── logbook.csv
    └── populations.csvEach item in the directory is described below:checkpoints: This directory contains the checkpoint files for each generation of the genetic optimization process. These files are used to save the state of the optimization process at each generation, allowing for the process to be resumed from a specific point if needed.cp_gen_0.pkl,cp_gen_1.pkl: These are the individual checkpoint files for each generation. They are named according to the generation number and are saved in Python's pickle format.graphics: This directory contains HTML files for visualizing the optimization process.logbook.html: This file provides a graphical representation of the logbook, which records the statistics of the optimization process over generations.search_space.html: This file provides a graphical representation of the search space of the optimization process.opt.log: This is the log file for the optimization process. It contains detailed logs of the optimization process, including the performance of the algorithm at each generation.progress: This directory contains CSV files that record the progress of the optimization process for each generation.Generation_0.csv,Generation_1.csv: These are the individual progress files for each generation. They contain detailed information about each individual in the population at each generation.results: This directory contains CSV files with the results of the optimization process.logbook.csv: This file is a CSV representation of the logbook, which records the statistics of the optimization process over generations.populations.csv: This file contains the final populations of the optimization process. It includes the hyperparameters and fitness values of each individual in the population.More details in thedocumentation.ExamplesExamples can be found inexampleson readthedocs.io.DependenciesThe following dependencies are used inmloptimizer:Deap- Genetic AlgorithmsXGBoost- Gradient boosting classifierScikit-Learn- Machine learning algorithms and utilitiesKeras- Deep learning libraryDocumentationThe documentation formloptimizercan be found in the project'swikiwith examples, classes and methods reference.AuthorsAntonio Caparrini-Owner-caparriniLicenseThis project is licensed under theMIT License.FAQsTODO