ArticleslgStudy

computer science

Optuna

Optuna is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Optuna rather than just read about it. In short: Optuna is an open-source Python library for automatic hyperparameter tuning of machine learning models. It was first introduced in 2018 by Preferred Networks, a Japanese startup that works on practical applications of deep learning in various fields.

Optuna — main illustration
Optuna — illustration

Key takeaways

  • Optuna belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Optuna to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Optuna from memory before moving on to harder problems.

Reference excerpt

Optuna is an open-source Python library for automatic hyperparameter tuning of machine learning models. It was first introduced in 2018 by Preferred Networks, a Japanese startup that works on practical applications of deep learning in various fields. The beta version of Optuna was released at the end of the year, with the subsequent first major stable release announced in January 2020.

Hyperparameter optimization

Hyperparameter optimization involves finding the optimal value of non-trainable parameters, defined by the user. Examples of hyperparameters are learning rate, number of layers or neurons, regularization strength, and tree depth. However, they strongly depend on the specific algorithm (e.g., classification, regression, clustering, etc.). Hyperparameter optimization can be especially relevant when dealing with large-scale problems or limited resources, as it improves model accuracy, reduces overfitting, and decreases training time. However, when the hyperparameter space increases, it may become computationally expensive. Hence, there are methods (e.g., grid search, random search, or bayesian optimization) that considerably simplify this process.

Features Optuna is designed to optimize the model hyperparameters by searching large spaces and discarding combinations that show no significant improvements in the model. Moreover, it can parallelize the hyperparameter search over multiple threads or processes. Optuna works with a high degree of modularity, allowing the definition of different configurations for searching hyperparameters. It is possible to choose which hyperparameters to optimize and how to optimize them. Additionally, it permits parameter customization at runtime, meaning that the values to explore for the hyperparameters (i.e., the search space) can be defined while writing the code, rather than being defined in advance.

Sampling Optuna exploits well-established algorithms to perform hyperparameter optimization, progressively reducing the search space in light of objective values. Examples are gaussian-process-based algorithms (i.e., a gaussian process to model the objective function), tree-structured parzen estimator (TPE) (i.e., a model-based optimization method that estimates the objective function and selects the best hyperparameters), and random search (i.e., a basic optimization approach used for benchmarking).

Early stopping

Optuna includes a pruning feature to stop trials early when the results show no significant improvement in the model. This allows for the prevention of unnecessary computation, and it is used for models with long training times in order to save time and computational resources. Specifically, Optuna exploits techniques such as median and threshold pruning.

Scalability Optuna is designed to scale with distributed computing resources, supporting parallel execution. This feature allows users to run optimization trials across multiple processors or machines.

Integration with third-part libraries Optuna integrates with various machine-learning (ML) libraries and frameworks:

Catboost Dask Fast.ai Keras LightGBM MLflow PyTorch PyTorch Ignite PyTorch Lightning TensorBoard TensorFlow tf.keras Weights & Biases XGBoost skrub Moreover, Optuna offers a real-time dashboard that allows a user to monitor, through graphs and tables, the optimization history and the hyperparameter importance.

Applications Optuna was designed to be framework-agnostic so that it can be used with any machine-learning (ML) or deep-learning (DL) framework.

Machine learning

Optuna can be used to optimize hyperparameters of ML models. Examples are:

Random forest: number of trees, maximum depth, and minimum samples per leaf. Gradient boosting machines (GBM): learning rate, number of estimators, and maximum depth. Support vector machines (SVM): regularization parameter (C), kernel type (e.g., linear, radial basis function), and gamma (gamma). K-nearest neighbors (KNN): number of neighbors (k), distance metrics (e.g., Euclidean or Manhattan), and weight function. Linear and logistic regression: alpha in Ridge Regression or C in Logistic Regression. Naive Bayes: smoothing coefficients.

Deep learning In the context of deep learning, Optuna can be exploited during the training of neural networks (NN) to optimize learning rate, batch size, and the number of hidden layers. For example, it can be used for:

Convolutional neural networks (CNNs), for image classification, object detection, and semantic-segmentation tasks. Recurrent neural networks (RNNs), for sequence-based tasks such as time-series forecasting and natural language processing. Transformers, for NLP tasks such as text classification, sentiment analysis, and machine translation.

Domains Optuna has found applications in various research studies and industry implementations across different applicative domains.

Healthcare In healthcare, Optuna is currently utilized for medical image analysis to optimize DL models for tumor detection, disease identification, multi-organ semantic segmentation, and radiological image analysis. It can also be implemented for disease prediction, in particular for the improvement in the accuracy of predictive models for disease diagnosis and treatment outcomes. Its application can also be found in genomics to predict genetic diseases and to identify genetic variations.

Finance In finance, Optuna is used to optimize models for algorithmic trading. It allows for predicting market movements due to its ability to handle wide parameter ranges and complex model structures. In particular, it is exploited for financial risk analysis and forecasting. Topics addressed are credit, market, and operational risks.

Autonomous systems Optuna is used for real-time applications in autonomous systems for robotics, supporting decision making in dynamic environments. It is also used in the context of self-driving cars to optimize the model to navigate safely in complex environments. For example, Optuna can be used in scenarios where there is the need to evaluate the rate and the severity of accidents or to address the issue of network intrusion attacks due to potential vulnerabilities.

… excerpt ends here. Continue reading the full article.

Illustrations

Optuna: Hyperparameter Optimization using Grid Search
Hyperparameter Optimization using Grid Search
Optuna: Hyperparameter Optimization using Tree-Structured Parzen Estimators
Hyperparameter Optimization using Tree-Structured Parzen Estimators
Optuna: Bayesian optimization of a function (black) with a gaussian process (purple). Three acquisition functions (blue).
Bayesian optimization of a function (black) with a gaussian process (purple). Three acquisition functions (blue).
Optuna: Standard pipeline for the optimization of hyperparameters for the training of a Decision Tree Classfier using Optuna
Standard pipeline for the optimization of hyperparameters for the training of a Decision Tree Classfier using Optuna

Worked examples

Example 1 — a first encounter with Optuna

Start with the simplest possible case. Write down what Optuna claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Optuna before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Optuna ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Optuna

In research
Optuna appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Optuna in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Optuna is common in secondary-school and first-year university syllabi. It links to neighbouring topics Deep learning software, Python (programming language) libraries, Software using the MIT license, so understanding it makes those chapters shorter.
In everyday life
Look for Optuna outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Optuna in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Optuna means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Optuna out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Optuna in simple terms?

Optuna is an open-source Python library for automatic hyperparameter tuning of machine learning models. It was first introduced in 2018 by Preferred Networks, a Japanese startup that works on practical applications of deep learning in various fields.

Why does Optuna matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Optuna?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Optuna.

Tags

  • Deep learning software
  • Python (programming language) libraries
  • Software using the MIT license

Keep exploring