optuna 4.3.0


pip install optuna

  Latest version

Released: Apr 14, 2025


Meta
Author: Takuya Akiba
Requires Python: >=3.8

Classifiers

Development Status
  • 5 - Production/Stable

Intended Audience
  • Science/Research
  • Developers

License
  • OSI Approved :: MIT License

Programming Language
  • Python :: 3
  • Python :: 3.8
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3 :: Only

Topic
  • Scientific/Engineering
  • Scientific/Engineering :: Mathematics
  • Scientific/Engineering :: Artificial Intelligence
  • Software Development
  • Software Development :: Libraries
  • Software Development :: Libraries :: Python Modules

Optuna: A hyperparameter optimization framework

Python pypi conda GitHub license Read the Docs Codecov

:link: Website | :page_with_curl: Docs | :gear: Install Guide | :pencil: Tutorial | :bulb: Examples | Twitter | LinkedIn | Medium

Optuna is an automatic hyperparameter optimization software framework, particularly designed for machine learning. It features an imperative, define-by-run style user API. Thanks to our define-by-run API, the code written with Optuna enjoys high modularity, and the user of Optuna can dynamically construct the search spaces for the hyperparameters.

:loudspeaker: News

:fire: Key Features

Optuna has modern functionalities as follows:

Basic Concepts

We use the terms study and trial as follows:

  • Study: optimization based on an objective function
  • Trial: a single execution of the objective function

Please refer to the sample code below. The goal of a study is to find out the optimal set of hyperparameter values (e.g., regressor and svr_c) through multiple trials (e.g., n_trials=100). Optuna is a framework designed for automation and acceleration of optimization studies.

Sample code with scikit-learn

Open in Colab

import ...

# Define an objective function to be minimized.
def objective(trial):

    # Invoke suggest methods of a Trial object to generate hyperparameters.
    regressor_name = trial.suggest_categorical('regressor', ['SVR', 'RandomForest'])
    if regressor_name == 'SVR':
        svr_c = trial.suggest_float('svr_c', 1e-10, 1e10, log=True)
        regressor_obj = sklearn.svm.SVR(C=svr_c)
    else:
        rf_max_depth = trial.suggest_int('rf_max_depth', 2, 32)
        regressor_obj = sklearn.ensemble.RandomForestRegressor(max_depth=rf_max_depth)

    X, y = sklearn.datasets.fetch_california_housing(return_X_y=True)
    X_train, X_val, y_train, y_val = sklearn.model_selection.train_test_split(X, y, random_state=0)

    regressor_obj.fit(X_train, y_train)
    y_pred = regressor_obj.predict(X_val)

    error = sklearn.metrics.mean_squared_error(y_val, y_pred)

    return error  # An objective value linked with the Trial object.

study = optuna.create_study()  # Create a new study.
study.optimize(objective, n_trials=100)  # Invoke optimization of the objective function.

[!NOTE] More examples can be found in optuna/optuna-examples.

The examples cover diverse problem setups such as multi-objective optimization, constrained optimization, pruning, and distributed optimization.

Installation

Optuna is available at the Python Package Index and on Anaconda Cloud.

# PyPI
$ pip install optuna
# Anaconda Cloud
$ conda install -c conda-forge optuna

[!IMPORTANT] Optuna supports Python 3.8 or newer.

Also, we provide Optuna docker images on DockerHub.

Integrations

Optuna has integration features with various third-party libraries. Integrations can be found in optuna/optuna-integration and the document is available here.

Supported integration libraries

Web Dashboard

Optuna Dashboard is a real-time web dashboard for Optuna. You can check the optimization history, hyperparameter importance, etc. in graphs and tables. You don't need to create a Python script to call Optuna's visualization functions. Feature requests and bug reports are welcome!

optuna-dashboard

optuna-dashboard can be installed via pip:

$ pip install optuna-dashboard

[!TIP] Please check out the convenience of Optuna Dashboard using the sample code below.

Sample code to launch Optuna Dashboard

Save the following code as optimize_toy.py.

import optuna


def objective(trial):
    x1 = trial.suggest_float("x1", -100, 100)
    x2 = trial.suggest_float("x2", -100, 100)
    return x1 ** 2 + 0.01 * x2 ** 2


study = optuna.create_study(storage="sqlite:///db.sqlite3")  # Create a new study with database.
study.optimize(objective, n_trials=100)

Then try the commands below:

# Run the study specified above
$ python optimize_toy.py

# Launch the dashboard based on the storage `sqlite:///db.sqlite3`
$ optuna-dashboard sqlite:///db.sqlite3
...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.

OptunaHub

OptunaHub is a feature-sharing platform for Optuna. You can use the registered features and publish your packages.

Use registered features

optunahub can be installed via pip:

$ pip install optunahub
# Install AutoSampler dependencies (CPU only is sufficient for PyTorch)
$ pip install cmaes scipy torch --extra-index-url https://download.pytorch.org/whl/cpu

You can load registered module with optunahub.load_module.

import optuna
import optunahub


def objective(trial: optuna.Trial) -> float:
    x = trial.suggest_float("x", -5, 5)
    y = trial.suggest_float("y", -5, 5)
    return x**2 + y**2


module = optunahub.load_module(package="samplers/auto_sampler")
study = optuna.create_study(sampler=module.AutoSampler())
study.optimize(objective, n_trials=10)

print(study.best_trial.value, study.best_trial.params)

For more details, please refer to the optunahub documentation.

Publish your packages

You can publish your package via optunahub-registry. See the OptunaHub tutorial.

Communication

Contribution

Any contributions to Optuna are more than welcome!

If you are new to Optuna, please check the good first issues. They are relatively simple, well-defined, and often good starting points for you to get familiar with the contribution workflow and other developers.

If you already have contributed to Optuna, we recommend the other contribution-welcome issues.

For general guidelines on how to contribute to the project, take a look at CONTRIBUTING.md.

Reference

If you use Optuna in one of your research projects, please cite our KDD paper "Optuna: A Next-generation Hyperparameter Optimization Framework":

BibTeX
@inproceedings{akiba2019optuna,
  title={{O}ptuna: A Next-Generation Hyperparameter Optimization Framework},
  author={Akiba, Takuya and Sano, Shotaro and Yanase, Toshihiko and Ohta, Takeru and Koyama, Masanori},
  booktitle={The 25th ACM SIGKDD International Conference on Knowledge Discovery \& Data Mining},
  pages={2623--2631},
  year={2019}
}

License

MIT License (see LICENSE).

Optuna uses the codes from SciPy and fdlibm projects (see LICENSE_THIRD_PARTY).

4.3.0 Apr 14, 2025
4.2.1 Feb 12, 2025
4.2.0 Jan 20, 2025
4.1.0 Nov 12, 2024
4.0.0 Sep 02, 2024
4.0.0b0 Jul 16, 2024
3.6.2 Jan 27, 2025
3.6.1 Apr 01, 2024
3.6.0 Mar 18, 2024
3.5.1 Jan 27, 2025
3.5.0 Dec 11, 2023
3.4.1 Jan 27, 2025
3.4.0 Oct 17, 2023
3.3.0 Aug 07, 2023
3.2.0 May 30, 2023
3.1.1 Apr 07, 2023
3.1.0 Jan 18, 2023
3.1.0b0 Dec 22, 2022
3.0.6 Mar 09, 2023
3.0.5 Dec 19, 2022
3.0.4 Dec 01, 2022
3.0.3 Oct 11, 2022
3.0.2 Sep 15, 2022
3.0.1 Sep 08, 2022
3.0.0 Aug 29, 2022
3.0.0rc0 Aug 08, 2022
3.0.0b1 Jun 06, 2022
3.0.0b0 Apr 12, 2022
3.0.0a2 Feb 14, 2022
3.0.0a1 Feb 07, 2022
3.0.0a0 Dec 06, 2021
2.10.1 Jun 13, 2022
2.10.0 Oct 04, 2021
2.9.1 Aug 03, 2021
2.9.0 Aug 02, 2021
2.8.0 Jun 07, 2021
2.8.0.dev0 Apr 05, 2021
2.7.0 Apr 05, 2021
2.6.0 Mar 08, 2021
2.5.0 Feb 01, 2021
2.4.0 Jan 12, 2021
2.3.0 Nov 04, 2020
2.2.0 Oct 05, 2020
2.1.0 Sep 07, 2020
2.0.0 Jul 29, 2020
2.0.0rc0 Jul 06, 2020
1.5.0 Jun 01, 2020
1.4.0 May 11, 2020
1.3.0 Apr 02, 2020
1.2.0 Mar 05, 2020
1.1.0 Feb 06, 2020
1.0.0 Jan 14, 2020
0.19.0 Nov 18, 2019
0.18.1 Nov 08, 2019
0.18.0 Nov 07, 2019
0.17.1 Oct 15, 2019
0.17.0 Oct 11, 2019
0.16.0 Sep 12, 2019
0.15.0 Aug 29, 2019
0.14.0 Aug 01, 2019
0.13.0 Jul 04, 2019
0.12.0 Jun 06, 2019
0.11.0 May 23, 2019
0.10.0 Apr 22, 2019
0.9.0 Mar 19, 2019
0.8.0 Feb 26, 2019
0.7.0 Jan 24, 2019
0.6.0 Jan 10, 2019
0.5.0 Dec 14, 2018
0.4.0 Dec 03, 2018
0.0.1 Oct 19, 2018

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
alembic (>=1.5.0)
colorlog
numpy
packaging (>=20.0)
sqlalchemy (>=1.4.2)
tqdm
PyYAML