Courseiva
PMLEChapter 7 of 16Objective 2.3

Hyperparameter Tuning and Optimization

How do you get a machine learning model to stop being mediocre and start being excellent without changing its core code? This is the core problem that hyperparameter tuning solves, and it is one of the most heavily tested skills in the Google Professional Machine Learning Engineer exam because it directly impacts the cost, time, and accuracy of your deployed model.

12 min read
Advanced
Updated Jul 23, 2026
Editorial oversight: Johnson Ajibi· Security Systems Architect · MSc IT Security · IEEE Senior Member

A simple way to picture Hyperparameter Tuning and Optimization

The Slow Cooker Chili Recipe Analogy

A slow cooker is a kitchen appliance that transforms raw ingredients into a finished meal with very little hands-on effort.

Imagine you are making chilli for a big party. You have a basic recipe with ingredients like beans, tomatoes, and mince. But your slow cooker model has a dial with three settings: 'Low', 'High', and 'Warm'. These settings are your hyperparameters. They are not part of the ingredients themselves, but they control the cooking process. If you choose 'Low', the chilli cooks for eight hours and the flavours deepen beautifully. If you choose 'High', it cooks in four hours, but the beans might not soften completely and the spices can taste raw. You cannot learn the right setting from the recipe book alone. You have to cook a small test batch on 'Low', taste it, then try another batch on 'High', and compare results. This trial-and-error process to find the perfect dial position is exactly what hyperparameter tuning does. You run the same model (your recipe) multiple times but change the control knob (the hyperparameter) each time, then pick the knob position that gives you the best, most delicious result. You never change the actual recipe ingredients (those are your model's internal weights, which the model learns by itself) – you only adjust the cooking settings that govern how the recipe is executed.

How It Actually Works

When you train a machine learning model, you give it a set of data and an algorithm. The algorithm has internal 'knobs' it learns by itself during training – these are called 'parameters' or 'weights'. For example, a linear regression model learns a slope and an intercept from the data. You do not tell it what the slope is; it calculates it.

However, there is a second category of knobs that you, the human engineer, must set before training even starts. These are called 'hyperparameters'. The model cannot learn them from the data. You have to choose them based on experience, intuition, or systematic experimentation. Common examples include the 'learning rate' (how big a step the model takes when correcting its mistakes), the 'number of trees' in a random forest model, or the 'batch size' (how many data samples the model looks at before updating its knowledge).

Why does this matter? The wrong hyperparameter setting can make your model learn nothing at all (underfitting) or memorise the training data perfectly but fail on new data (overfitting). The right setting can turn a model that is 60% accurate into one that is 95% accurate. That difference can save a company millions or prevent a disaster in a self-driving car.

Traditionally, engineers would hand-tune hyperparameters. They would run a model, look at the results, make a guess, change a number, and run it again. This is slow, relies on luck, and does not scale when you have a dozen hyperparameters to tune at once.

Vertex AI automates this process with a service called 'Vertex AI Vizier'. Think of Vizier as an automatic chef that tastes your chilli a thousand times, records which dial settings produced the best flavour, and then recommends the best settings for your full batch. Here is how it works on Vertex AI:

You define a 'study' in the Google Cloud console. This study is your tuning experiment. You tell it which hyperparameters you want to tune (for example, 'learning rate' between 0.001 and 0.1, and 'batch size' between 16 and 128).

You choose a 'goal'. Typically this is 'MAXIMIZE' a metric like 'accuracy' or 'MINIMIZE' a metric like 'loss' (a measure of error).

Vertex AI Vizier then runs multiple 'trials'. Each trial trains the same model architecture with a different combination of hyperparameters. It does not try random combinations blindly. It uses a sophisticated algorithm called 'Bayesian optimisation' (a mathematical strategy that learns from past trials and guesses which new hyperparameter combinations are most likely to be good).

After a set number of trials, Vizier outputs the best hyperparameter values it found. You then use those values to train your final, production-ready model.

This replaces the old manual guesswork with an automated, data-driven search. It is faster, more thorough, and finds better hyperparameter combinations than even a very experienced human engineer could.

The three main search strategies you need to know for the PMLE exam are:

Grid search: Tries every single combination of hyperparameter values in a defined grid. Example: if you try learning rates [0.01, 0.1, 1.0] and batch sizes [16, 32, 64], grid search runs 3 x 3 = 9 trials. This is thorough but can be very expensive and slow with many hyperparameters.

Random search: Picks random combinations within the defined ranges of each hyperparameter. Research shows random search often finds good combinations faster than grid search because it covers more of the search space efficiently.

Bayesian optimisation: This is the smart algorithm used by Vertex AI Vizier. It builds a probability model of which hyperparameter combinations are likely to be good, based on results from previous trials. It then tries the most promising combinations, making it far more efficient than grid or random search, especially when each training trial is expensive to run.

For the exam, remember that Vertex AI Vizier uses Bayesian optimisation by default and that is the method Google recommends for most production use cases.

This flowchart shows the iterative process of hyperparameter tuning on Vertex AI, from defining the study and running trials in parallel to using Bayesian optimisation to guide subsequent trials until the budget is exhausted, then deploying the best settings for final training.

Walk-Through

1

Define the Study

In the Vertex AI console or using the SDK, you create a 'study' which is the container for your entire tuning experiment. You give it a name and specify whether you want to maximise or minimise a specific metric (for example, maximise accuracy or minimise loss). This is the first step because it sets the structure for everything that follows.

2

Configure the Search Space

You tell Vertex AI which hyperparameters you want to tune and the range of values to explore for each. For continuous parameters (like learning rate), you define a minimum and maximum. For discrete parameters (like number of layers), you list the exact integer values. This step is critical because an incorrectly defined search space might exclude the best settings entirely.

3

Set the Algorithm and Budget

You choose the search algorithm (almost always Bayesian optimisation for production use) and set the maximum number of trials and the maximum number of parallel trials. The budget of trials determines how many models will be trained. More trials increase the chance of finding a great combination but also increase cost. Parallel trials control how many train at the same time.

4

Run the Tuning

You launch the study. Vertex AI spins up compute resources and begins training trials. As trials complete, the Bayesian algorithm updates its internal model of which hyperparameter areas look promising and launches new trials in those areas. Early stopping may cancel ongoing trials that are clearly underperforming, freeing up resources for better candidates.

5

Analyse Results and Extract Best Hyperparameters

After all trials finish, the Vertex AI console displays a results table. You identify the trial with the best objective metric value. You note down the specific hyperparameter values from that trial. You do not deploy the model from the best trial itself because that model was only trained on a partial dataset.

6

Retrain and Deploy the Final Model

You take the best hyperparameters found in step 5 and use them to train your model on the entire training dataset (not the validation subset). This final, fully trained model is then deployed to production. This step ensures the model has seen all available data while benefiting from the optimised hyperparameters.

What This Looks Like on the Job

Sarah is a machine learning engineer at a large online retailer. The company wants to build a model that predicts whether a customer will buy a product within the next 30 days based on their browsing history. The model is a deep neural network with hundreds of thousands of parameters the network will learn on its own. But Sarah must decide on three hyperparameters: the learning rate, the number of hidden layers, and the dropout rate (a technique to prevent overfitting).

If Sarah guesses the learning rate too high, the model might overshoot the best solution and never converge. If she guesses too low, training could take weeks. If she chooses too many hidden layers, the model might memorise the training data and fail on real customers. Too few layers, and the model might not be smart enough to capture the patterns.

Sarah does not guess. She goes to Vertex AI and does the following step by step:

Step 1: She creates a new 'Training Pipeline' in Vertex AI and uploads her training data.

Step 2: She enables 'Hyperparameter Tuning' and defines her study. She sets the algorithm to 'ALGORITHM_UNSPECIFIED' (which lets Vertex AI choose Bayesian optimisation). She defines the ranges for her three hyperparameters. For learning rate, she sets a range from 0.0001 to 0.01. For hidden layers, she sets integer values of 2, 3, or 4. For dropout rate, she sets a continuous range from 0.2 to 0.5.

Step 3: She sets the maximum number of trials to 20 and the maximum number of parallel trials to 5. (Running trials in parallel saves wall-clock time, but she cannot run too many at once because each trial needs significant compute resources.)

Step 4: She specifies her objective metric. She chooses to 'MAXIMIZE' 'accuracy' on a validation dataset that her model will evaluate after each trial.

Step 5: She clicks 'Start'. Vertex AI spins up 5 compute instances, each training a model with different hyperparameter settings. After the first 5 trials finish, Vizier analyses the results and decides which new combinations to try in the next batch. This continues until all 20 trials are complete.

Step 6: After about two hours, the experiment finishes. Sarah looks at the 'Trial Results' table in the Vertex AI console. She sees that Trial #14 achieved 91% validation accuracy with a learning rate of 0.004, 3 hidden layers, and a dropout rate of 0.3. She uses these exact hyperparameters to train her final model on the full dataset.

Step 7: She deploys the final model and it performs just as well on live customer traffic, increasing the retailer's conversion rate predictions by 15%.

Without hyperparameter tuning, Sarah would have needed weeks of trial and error. With Vertex AI, she did it in hours and got a documented, reproducible result she could present to her manager.

How PMLE Actually Tests This

The PMLE exam tests hyperparameter tuning heavily. Here is exactly what you need to know.

First, the exam asks you to choose between the three search strategies. A typical question might describe a scenario with a very expensive model that takes hours to train. The question will ask: 'Which search strategy should you use?' The correct answer is always Bayesian optimisation because it is the most efficient (requires fewer trials to find a good result). Random search is a distractor answer the exam uses for moderately expensive models. Grid search is only correct when the number of hyperparameters is very small (like 2 or 3) and the budget is large. Memorise this hierarchy: Bayesian = smart and efficient for expensive models, Random = good balance for medium cost, Grid = only for small search spaces.

Second, expect questions about 'early stopping'. This is a technique where Vertex AI stops a trial early if it is clearly performing poorly. The exam loves this because it saves money. A trap question will describe running many trials without early stopping and ask you to identify the inefficiency. The correct answer pattern is to always enable early stopping when using Bayesian optimisation.

Third, the exam tests the concept of 'parallel trials'. Running too many trials in parallel can actually hurt the effectiveness of Bayesian optimisation because the algorithm needs results from one trial to decide the next. If you run 50 trials all at once, it is just random search. The correct answer pattern for a question about high parallelism is: reduce the number of parallel trials to allow the algorithm to learn from each trial before launching the next batch.

Fourth, you will see questions about 'hp_metric' or 'metric_spec' in training container definitions. The exam expects you to know that the metric your tuning optimises must be reported back by your training code as a specific string (for example, 'accuracy' or 'loss'). If the training code does not export that metric, Vertex AI cannot optimise it. The trap is that the exam will give you a code snippet where the metric name in Vertex AI's configuration does not match the metric name logged in the training code. The correct answer is to ensure they match exactly.

Key definitions to memorise:

Study: The entire tuning experiment on Vertex AI.

Trial: A single training run with one specific hyperparameter combination.

Objective metric: The number you are trying to make better (for example, accuracy or loss).

Bayesian optimisation: The default and recommended algorithm in Vertex AI Vizier.

Search space: The range of possible values for each hyperparameter.

Early stopping: Automatically cancels a poorly performing trial to save resources.

Parallel trial count: The number of trials running at the same time.

Finally, the exam will test that you understand that hyperparameter tuning happens *after* you have prepared your data and chosen your model architecture, but *before* you deploy the final model. It is step 3 of a 5-step pipeline: data preparation, model architecture selection, hyperparameter tuning, final training, and deployment.

Key Takeaways

Hyperparameters are configuration settings you choose before training starts, while model parameters (weights) are learned from the training data automatically.

Vertex AI Vizier uses Bayesian optimisation by default, which efficiently learns from past trials to suggest better hyperparameter combinations, not random guesses.

Grid search tries every combination and is only practical for a very small number of hyperparameters, while random search scales better for larger search spaces.

Early stopping automatically cancels poorly performing trials during tuning, saving both money and compute time without sacrificing final model quality.

The hyperparameters found by the best trial must be used to retrain the model on the full dataset before deployment do not deploy the model from the tuning trial itself.

Setting too many parallel trials (for example, running all trials at once) turns Bayesian optimisation into random search, nullifying its main advantage of guided exploration.

The objective metric you optimise must be logged by your training code with an exact name that matches the metric name defined in the Vertex AI study configuration.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Hyperparameter

Set by the human before training starts

Controls the learning process (e.g., learning rate)

Cannot be learned from data

Model Parameter (Weight)

Learned by the model during training from the data

Defines the model's internal representation (e.g., slope in regression)

Automatically adjusted by the training algorithm

Grid Search

Exhaustively tries every combination in a defined grid

Very expensive for more than 3 hyperparameters

Works well when you have a small search space and large budget

Bayesian Optimisation

Builds a probabilistic model to predict good combinations

Much more efficient, requires fewer trials

Adapts based on previous results; the default in Vertex AI Vizier

Random Search

Picks hyperparameter values uniformly at random

No learning from past trials

Can work well as a baseline but less efficient than Bayesian

Bayesian Optimisation

Uses past results to focus on promising regions of the search space

Learns and adapts as new trials complete

Recommended for expensive models and is the Vertex AI default

Parallel Trials (High Count)

Runs many trials at the same time (e.g., 20 out of 20)

Defeats Bayesian optimisation (becomes random search)

Faster wall-clock time but potentially worse final result

Parallel Trials (Moderate Count)

Runs a smaller number (e.g., 5 out of 20)

Allows Bayesian optimisation to learn sequentially

Slower wall-clock time but finds better hyperparameters

Watch Out for These

Mistake

Hyperparameter tuning and model training are the same thing.

Correct

Model training is when the model learns internal weights from the data. Hyperparameter tuning is a separate outer loop that finds the best settings for the training process itself. They are two distinct phases.

Both involve running the training code, so beginners conflate them into one activity. They think that tuning is just 'more training' when it is actually a search over training configurations.

Mistake

Grid search is always the best method because it tries every combination.

Correct

Grid search is only suitable when you have a very small number of hyperparameters (2-3) and sufficient budget. For most real-world problems with many hyperparameters, random search and especially Bayesian optimisation are far more efficient.

The word 'comprehensive' sounds good, so beginners assume exhaustive is superior. They miss the huge computational cost of grid search when you have, say, 10 hyperparameters with 10 values each (10^10 trials).

Mistake

Once Vertex AI finishes tuning, I should use the exact hyperparameters from the best trial for my final model without retraining.

Correct

The best trial is trained on a subset of the training data (often 80%). You must take those best hyperparameters and retrain the model on the entire dataset. The best trial's model should not be deployed directly.

The Vertex AI interface shows the best trial's results prominently, and beginners assume those results are the final model. They forget that the tuning phase uses a held-out validation set that the final model never gets to see.

Mistake

I can set the parallel trial count as high as I want to speed things up.

Correct

Setting parallel trials too high (for example, equal to the total number of trials) defeats the purpose of Bayesian optimisation because the algorithm needs results from completed trials to guide new trials. It effectively becomes random search, and you lose the efficiency benefit.

The desire to finish faster makes beginners assume parallel always helps. They do not understand that Bayesian optimisation is sequential and self-correcting.

Mistake

Hyperparameters and model parameters are exactly the same thing.

Correct

Model parameters (weights) are learned from data during training. Hyperparameters are set by the engineer before training and control how the learning process works. The model cannot learn hyperparameters from data.

The word 'parameter' is used in both contexts confusingly. Many training frameworks also call hyperparameters 'arguments', which further blurs the line.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

What is the difference between a hyperparameter and a model parameter?

A model parameter (or weight) is learned from the training data automatically, like the slope in a linear regression. A hyperparameter is a setting you choose before training, like the learning rate. The model cannot learn hyperparameters from data.

Does Vertex AI have a built-in hyperparameter tuning service?

Yes, the service is called Vertex AI Vizier. It is fully managed and uses Bayesian optimisation by default. You can access it from the Google Cloud console, the Python SDK, or via REST API.

What is early stopping in hyperparameter tuning?

Early stopping is when Vertex AI automatically cancels a trial that is clearly performing poorly before it finishes. This saves money and compute time because resources can be redirected to more promising trials.

Should I use grid search or Bayesian optimisation for my tuning?

Use Bayesian optimisation (Vertex AI Vizier default) for most cases, especially when training is expensive or you have many hyperparameters. Grid search is only appropriate when you have 2 or 3 hyperparameters and a large budget, because it tries every combination linearly.

Can I run all my tuning trials in parallel to make it finish faster?

You can, but you should not. Running all trials in parallel turns Bayesian optimisation into random search because the algorithm cannot use results from one trial to inform the next. A moderate number of parallel trials (for example, 5-10) with sequential learning is more efficient.

Do I deploy the model from the best tuning trial directly?

No. The best trial's model was trained on a subset of your data. You must take the best hyperparameters from that trial and retrain a new model on the full training dataset before deploying it to production.

Terms Worth Knowing

Keep going

You've finished Hyperparameter Tuning and Optimization. Continue through the PMLE study guide to build a complete picture of the exam.

Done with this chapter?