Courseiva
MLA-C01Chapter 6 of 16Objective 2.2

Hyperparameter Tuning and Model Optimization

Hyperparameter tuning and model optimisation let you squeeze the best possible performance out of a machine learning model by adjusting its control dials, not its internal weights. For the MLA-C01 exam, this topic matters because AWS specifically tests whether you can configure automatic model tuning jobs in SageMaker, choose the right search strategy, and avoid common pitfalls that waste money or produce unreliable results.

12 min read
Intermediate
Updated Jul 23, 2026
Reviewed by Johnson Ajibi· Senior Network & Security Engineer · MSc IT Security

A simple way to picture Hyperparameter Tuning and Model Optimization

The Slow Cooker Chili Recipe Analogy

Setting your initial hyperparameters is like picking the first recipe for a slow cooker chili without knowing anyone's taste. You guess the amount of chilli powder (the learning rate), the number of beans (the number of trees in a random forest), and the cooking time (the number of epochs). The first batch comes out bland, so you have to adjust.

What you do next is the real optimisation: you run a series of test batches, each with a slightly different spice mix or cooking duration, and you ask a panel of neighbours (the validation set) to rate each one. You notice that when you double the cumin, the bitterness score drops fast, so you 'tune' towards that direction. But you also learn that if you cook it for eight hours instead of four, the meat becomes tough — that is overfitting to the recipe. You stop the experiments when the ratings plateau, just like Amazon SageMaker stops when performance stops improving.

This process mirrors hyperparameter tuning on the AWS exam: you have a search space (all the possible ingredient amounts), a strategy (either random sampling or Bayesian search), and an objective metric (taste score). The trick is to avoid brute-forcing every combination — that takes too long and wastes compute — and instead use a smart strategy that narrows the good region quickly.

How It Actually Works

To understand hyperparameter tuning, you first need to know the difference between a model's internal parameters and its hyperparameters.

Internal parameters (like the weights in a neural network) are learned automatically from the training data — the model discovers them during training and you never set them manually. Hyperparameters, on the other hand, are settings you choose before training begins. They control how the model learns. Examples include the learning rate (how big a step the model takes when adjusting its internal parameters), the number of trees in a random forest (more trees usually mean more accuracy but also more processing time), and the batch size (how many training examples the model looks at before updating its internal weights).

The default hyperparameters that come with a library (like Scikit-learn or XGBoost) often work reasonably well on a basic dataset, but they are rarely optimal for your specific problem. If you use the defaults on a business dataset with thousands of features, the model might converge slowly, overfit to noise, or never reach the performance you need. Hyperparameter tuning is the systematic search for the combination of hyperparameter values that gives you the best validation score.

AWS SageMaker handles this with a feature called Automatic Model Tuning (AMT). You define three things:

A search space: the range of possible values for each hyperparameter you want to tune. For example, you might tell SageMaker to try learning rates between 0.001 and 0.1, and numbers of trees between 100 and 500.

A tuning strategy: how SageMaker selects the next combination to try. There are three main strategies.

A resource limit: the maximum number of training jobs (trials) you are willing to run.

The three tuning strategies you need for the MLA-C01 exam are:

Random search: SageMaker picks combinations at random from your search space. It is simple, parallelisable (you can run many trials at once), and works well when you have many hyperparameters because it covers the space evenly.

Grid search: SageMaker tries every combination in a fixed set of discrete values. For example, if you specify learning rates [0.001, 0.01, 0.1] and batch sizes [32, 64, 128], it will try all nine combinations. This is exhaustive but extremely wasteful in high-dimensional spaces — it grows exponentially with the number of hyperparameters.

Bayesian optimisation: SageMaker uses a probabilistic model (a Gaussian process) to guess which combination will improve performance the most, then tests that guess. Over time it focuses on the most promising region of the search space. This typically finds a good configuration in fewer trials than random or grid search, but it cannot run trials in parallel as easily because each trial's outcome is used to inform the next suggestion.

Beyond the strategy, you must also handle early stopping. Early stopping means terminating a trial early if its performance is clearly going to be worse than the best trial so far. SageMaker can do this automatically: after a few epochs, if the validation score is still far below the current best, SageMaker kills that trial and moves on. This saves compute time and money.

A crucial concept on the exam is the objective metric. This is the single number you want to optimise, like validation accuracy or mean squared error (MSE). You tell SageMaker whether you want to maximise it (higher accuracy is better) or minimise it (lower MSE is better). If you optimise for the wrong metric, you might end up with a model that scores well on one measure but poorly on what actually matters for your business.

Finally, be careful about overfitting during tuning. If you tune hyperparameters directly on your test set, you will get an overly optimistic estimate of real-world performance. The correct workflow is: split your data into training, validation, and test sets. Use the validation set inside the tuning loop. Evaluate the final selected model on the held-out test set, once, at the very end.

Flowchart showing the hyperparameter tuning process in SageMaker, from defining the search space through selecting a strategy, running trials, and final model evaluation.

Walk-Through

1

Define the objective metric

Choose a single metric (e.g. validation accuracy, mean squared error) that the tuning job will optimise. Specify whether to maximise or minimise it. This metric must be logged in your training script so SageMaker can capture it.

2

Choose the search space

Define the range or set of possible values for each hyperparameter you want to tune. For example, learning rate between 0.001 and 0.1, batch size options [32, 64, 128]. A well-designed search space balances coverage with efficiency.

3

Select a tuning strategy

Pick random search, grid search, or Bayesian optimisation based on your budget and the number of hyperparameters. Random search works well for many hyperparameters; Bayesian optimisation is good when trials are expensive.

4

Set resource limits and early stopping

Configure MaxNumberOfTrainingJobs (total trials) and MaxParallelTrainingJobs (how many run at once). Enable early stopping to kill trials that are clearly not improving, saving compute and time.

5

Launch the tuning job and monitor results

Run the tuning job in SageMaker. Monitor the progress via logs or the SageMaker console. Once completed, review the best trial's configuration and evaluate it on the held-out test set.

What This Looks Like on the Job

An IT professional working as a Machine Learning Engineer at an e-commerce company is tasked with building a product recommendation model. The data includes customer purchase history, browsing behaviour, and product metadata. The initial model, using default XGBoost hyperparameters, achieves a recommendation accuracy of 68% on the validation set — not good enough for the business requirement of 80%.

Here is how the engineer would use hyperparameter tuning to improve that score:

First, the engineer launches a SageMaker notebook and loads the training and validation datasets into an S3 bucket. They then define a tuning job using the SageMaker SDK. The search space includes:

eta (learning rate): a continuous range from 0.01 to 0.3

max_depth: integer values from 3 to 10

subsample: a continuous range from 0.5 to 1.0

colsample_bytree: a continuous range from 0.3 to 0.9

gamma: a continuous range from 0 to 5

The engineer chooses Bayesian optimisation as the strategy because they have a limited budget of 30 training jobs and want to find a good configuration quickly. The objective metric is set to 'validation:auc' (area under the ROC curve) with the goal of maximising it.

The tuning job runs across the 30 trials. SageMaker starts with a few random points to build the initial Gaussian process model, then begins suggesting configurations that are likely to increase AUC. After trial 12, the AUC reaches 0.82. After trial 18, it plateaus at 0.84. SageMaker detects that the improvements have become negligible and suggests stopping further trials to save compute. The engineer approves the early stopping and selects the configuration from trial 18.

The engineer then trains the final model using those hyperparameters on the combined training and validation datasets, and evaluates it once on the held-out test set. The test AUC is 0.83, meeting the business requirement.

Common real-world steps the engineer must remember:

Log the objective metric correctly in the training script using the SageMaker metric definitions

Set a maximum number of training jobs to control cost

Use early stopping to avoid wasting compute on bad trials

Choose a sensible search space — too wide wastes trials, too narrow misses good options

Always separate test data from the tuning loop

How MLA-C01 Actually Tests This

The MLA-C01 exam tests hyperparameter tuning in a very specific and predictable way. Questions on this topic appear mostly as multiple-choice single-answer, multiple-choice multiple-answer, and occasionally as scenario-based questions where you have to pick the right configuration steps.

Here are the exact concepts the exam loves:

Differences between random search, grid search, and Bayesian optimisation. You must know that grid search is exhaustive and expensive, random search is parallelisable and works well for high-dimensional spaces, and Bayesian optimisation is sample-efficient but harder to parallelise.

The definition of the objective metric and how to specify maximisation vs minimisation. A trap question might describe a metric like mean squared error and ask whether you set the objective to 'Maximize' or 'Minimize'. The answer is always 'Minimize' for MSE.

Early stopping in the context of SageMaker tuning jobs. The exam may ask: 'What configuration parameter enables SageMaker to stop training jobs that are unlikely to improve performance?' The answer is 'Early stopping type' or 'Stopping condition'.

The distinction between tuning hyperparameters (like learning rate, batch size) and model architecture hyperparameters (like number of layers, number of units in a layer). Both types appear, but SageMaker tuning works on any parameter you expose.

The importance of the warm start feature. If you already ran a tuning job and want to extend it, you can reuse previous results with 'WarmStartConfig' to continue searching where you left off. The exam may ask when to use warm start vs starting fresh.

Resource limits: the 'MaxNumberOfTrainingJobs' and 'MaxParallelTrainingJobs' parameters. The exam tests whether you know that increasing parallel jobs speeds up wall-clock time but does not change the total number of trials.

Common trap patterns to watch for:

They present a scenario where the data is small and ask for the best tuning strategy. The trick is that Bayesian optimisation may overfit noisy patterns on very small datasets, so random search with a higher number of trials is safer.

They describe a tuning job that ran for 100 trials and achieved a certain validation score, then ask what to do next. The wrong answer is 'Use the same configuration on the training set again' — the correct answer is 'Evaluate the tuned model on the test set once'.

They list a set of hyperparameters and ask which one is NOT tunable by SageMaker — sometimes they include 'batch size' as tunable, which it is. A trap might be 'number of epochs', which can also be a hyperparameter.

Key definitions to memorise:

Tuning job: a SageMaker resource that orchestrates multiple training jobs to find the best hyperparameter combination.

Search space: the range of values for each hyperparameter to explore.

Objective metric: the single metric used to evaluate each trial's performance.

Early stopping: terminating a trial early when it is not improving relative to the best trial.

Warm start: continuing a previous tuning job with additional trials.

Random search: selecting hyperparameter combinations uniformly at random from the search space.

Grid search: trying all possible combinations of specified discrete values.

Bayesian optimisation: using a probabilistic model to suggest the next promising combination.

Key Takeaways

Hyperparameters are the settings you choose before training starts, unlike model weights which are learned from data.

The three main tuning strategies in SageMaker are random search, grid search, and Bayesian optimisation, each with different trade-offs between thoroughness and speed.

Grid search becomes exponentially expensive as the number of hyperparameters increases — random search is often more practical.

Bayesian optimisation uses a probabilistic model to suggest promising hyperparameter combinations, reducing the number of trials needed.

Early stopping terminates unpromising training jobs early to save compute time and cost.

The objective metric must be defined before tuning and cannot be changed mid-job.

The test dataset must never be used during tuning — it is only for final evaluation after the best hyperparameters are chosen.

Warm start lets you continue a previous tuning job with additional trials, reusing past results to guide the search.

Easy to Mix Up

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

Random Search

Selects hyperparameter values uniformly at random from the search space

Works well with high-dimensional search spaces (many hyperparameters)

Can be parallelised efficiently because trials are independent

Grid Search

Tries every combination of specified discrete values

Becomes exponentially expensive as the number of hyperparameters increases

Cannot be effectively parallelised beyond the number of grid combinations

Hyperparameter

Set manually before training begins

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

Not learned from the training data

Model Parameter

Learned automatically during training from the data

Represents the internal state of the model (e.g., weights, coefficients)

Can have millions or billions of values in a deep neural network

Validation Set

Used repeatedly during hyperparameter tuning to evaluate trials

Influences the choice of hyperparameters

Part of the tuning loop

Test Set

Used exactly once at the end to estimate real-world performance

Must never be used in tuning decisions

Isolated from the entire training and tuning process

Watch Out for These

Mistake

Hyperparameters are automatically learned from the training data just like model weights.

Correct

Hyperparameters are manually set before training begins and control the learning process itself, while model weights are learned during training.

Beginners hear the word 'parameters' and assume all parameters are learned. The distinction between learned parameters and hyperparameters is one of the first conceptual hurdles in machine learning.

Mistake

Grid search is always better because it is thorough and does not miss the optimal combination.

Correct

Grid search is exhaustive only for the discrete values you specify. It becomes impractical when you have many hyperparameters because the number of combinations grows exponentially (the curse of dimensionality). Random search often finds a good configuration faster.

People intuitively think trying every possibility guarantees success, but they underestimate how many possibilities there are once you have more than two or three hyperparameters.

Mistake

The objective metric can be changed during a tuning job based on early results.

Correct

The objective metric must be defined before the tuning job starts. You cannot change it mid-job — you would need to start a new tuning job with the new metric.

This mistake comes from confusing adaptive planning (changing course based on data) with the fixed structure of a SageMaker tuning job, which requires all configuration upfront.

Mistake

You should tune hyperparameters on the test dataset to make sure the final model performs well on unseen data.

Correct

You should never tune hyperparameters on the test dataset. The test set must be kept completely separate as a final unbiased evaluation. Tuning on test data causes overfitting to the test set.

This mistake arises from a misunderstanding of the data split hierarchy. Beginners think the test set is a 'final check' but then use it repeatedly during tuning, which invalidates the evaluation.

Mistake

Bayesian optimisation always finds the optimal hyperparameters with the fewest trials, regardless of the data size.

Correct

Bayesian optimisation works well when you have enough data to build a reliable probabilistic model. On very small datasets or with noisy objective functions, random search can be more robust and less prone to overfitting the search surface.

The promise of Bayesian optimisation sounds magical, so learners assume it is universally superior. They overlook that it is a statistical method that itself requires sufficient data to work well.

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

How do I choose between random search and Bayesian optimisation for hyperparameter tuning?

Use random search when you have many hyperparameters (more than 5) and a limited budget of trials, because it covers the space evenly. Use Bayesian optimisation when each trial is expensive (e.g., large deep learning models) and you want to find a good configuration with as few trials as possible.

Can I run multiple tuning jobs in parallel in SageMaker?

Yes, you can set MaxParallelTrainingJobs in your tuning job configuration. However, note that Bayesian optimisation cannot effectively suggest new trials for all parallel jobs at once because it needs the results of one trial before suggesting the next.

What happens if my tuning job finishes but the performance is still not good enough?

You can extend the tuning job using WarmStartConfig to continue searching from where you left off. Alternatively, you can redefine the search space (widen it or focus on different hyperparameters) and start a new tuning job.

Do I need to tune all hyperparameters for every model?

No, you only need to tune hyperparameters that significantly affect performance. Many models have default values that work well. Start with the most impactful ones like learning rate, number of trees, or regularisation strength.

How do I avoid overfitting when tuning hyperparameters?

Always use a separate validation set for tuning. Never use the test set during the tuning process. Evaluate your final model on the test set exactly once. Also, use cross-validation inside the tuning loop if your dataset is small.

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

A hyperparameter is a setting you choose manually before training, like learning rate or batch size. A model parameter is learned automatically during training from the data, like the weights in a neural network or the coefficients in linear regression.

Can tuning improve a model that already has 99% accuracy?

It is possible but usually diminishing returns. At high accuracy, even a small improvement (e.g., 99.1% to 99.2%) can be valuable in applications like fraud detection or medical diagnosis. However, the risk of overfitting to the validation set increases.

Terms Worth Knowing

Keep going

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

Done with this chapter?