Optuna is an automatic hyperparameter optimization framework for machine learning, featuring an imperative, define-by-run style user API that allows for dynamic construction of search spaces. It supports Python 3.9 or newer. The current version is 4.8.0, and it maintains an active development and release cadence, with major versions often introducing significant improvements and deprecating older features after a few releases.
pip install optunaVerified import paths — ran on the pinned version, not inferred.
This quickstart defines an objective function that trains either an SVR or RandomForestRegressor, with hyperparameters sampled by Optuna's `Trial` object. It then creates a study to minimize the mean squared error over 100 trials, showcasing how Optuna dynamically builds search spaces and finds optimal hyperparameters.
Review the Optuna v4 Migration Guide. For multi-objective optimization, the functionality was integrated into the single-objective API in v2.4.0, so adapt your code to use the unified API.
Update import paths and argument signatures for `IntersectionSearchSpace` and `intersection_search_space` to reflect their new locations and API changes.
Upgrade your Python environment to Python 3.9 or newer.
Ensure all arguments for samplers are passed as keyword arguments and review sampler-specific documentation for changes in argument behavior or deprecations.
When performing multi-objective optimization, be mindful of scheduler compatibility. Consider using samplers and pruners specifically designed or enhanced for multi-objective tasks (e.g., `GPSampler` with multi-objective support from v4.4).
Ensure all necessary external dependencies are installed in your environment. For `sklearn`, install it using `pip install scikit-learn`.
Ensure the `scikit-learn` package is installed in your Python environment if you are using Optuna features that rely on it (e.g., `pip install scikit-learn`).
Ensure Optuna is installed in your active Python environment using `pip install optuna`. If using a virtual environment or IDE, verify that the correct environment/interpreter is selected.
Upgrade your Optuna library to a recent version using `pip install --upgrade optuna`. If the sampler was deprecated or renamed, refer to the official Optuna documentation for the correct class name or usage (e.g., `GridSampler` is available in newer versions).
Replace `trial.suggest_loguniform(name, low, high)` with `trial.suggest_float(name, low, high, log=True)`. Similarly, `suggest_uniform` is replaced by `suggest_float` without `log=True`.
For parallel optimization, use a more robust RDB backend like PostgreSQL or MySQL instead of SQLite. If you must use a file-based storage, consider `JournalFileStorage` for multi-processing or ensure sequential access to the SQLite database. You can also try increasing the database connection timeout with `engine_kwargs={'connect_args': {'timeout': 10}}` in `optuna.storages.RDBStorage`.For multi-objective studies, use the plural attributes such as `study.best_trials` to retrieve the Pareto front, and `study.directions` to get all objective directions. If you intend a single-objective study, ensure it is configured with a single objective direction when created (e.g., `optuna.create_study(direction='maximize')`).