What the exam expects you to do
This module covers hyperparameter tuning from task 2.2 and all of task 2.3 (analyze model performance). After it you should be able to do each of these without notes:
- Pick a tuning strategy, set ranges and scaling, and reuse earlier tuning with warm start.Tuning
- Work out precision, recall, F1 and the rest from a confusion matrix.Metrics
- Set a decision threshold from business costs or review capacity.Threshold
- Compare candidate models fairly against baselines.Comparing
- Read training curves: overfitting, underfitting, learning rate problems.Diagnostics
- Explain one prediction and the model as a whole.Explaining
- Measure fairness in a model’s predictions.Fairness
- Version, approve and roll back models with Model Registry.Registry
- Choose metrics for regression, generated text, foundation models and RAG; shadow vs A/B tests.Deep dives
Everything to recall on one screen
Each line maps an exam phrase to the answer it usually points to.
If the question says… pick
| “Tune hyperparameters, learn from earlier trials” | AMT, Bayesian strategy |
| “Run as many trials in parallel as possible” | Random search |
| “Deep learning; stop weak trials after a few epochs” | Hyperband (set early stopping to OFF) |
| “Try every combination of a few categorical values” | Grid search (categorical only) |
| “Continue a previous tuning job” | Warm start, IDENTICAL_DATA_AND_ALGORITHM |
| “Re‑tune on new data, reuse what was learned” | Warm start, TRANSFER_LEARNING |
| “Learning rate range spans 0.0001 to 0.1” | Logarithmic scaling |
| “Stop poor training jobs early to save cost” | Tuner early stopping = Auto |
| “Rare positive class; one summary number” | PR‑AUC (not accuracy, not ROC‑AUC alone) |
| “Missing a positive is very costly” | Prioritize recall; lower the threshold |
| “False alarms are very costly” | Prioritize precision; raise the threshold |
| “Balance precision and recall in one number” | F1 |
| “Reviewers can handle only N alerts a day” | Set the threshold by capacity (top N scores) |
| “Different costs for FP and FN” | Choose the threshold that minimizes expected cost |
| “Predict a number; penalize big errors more” | RMSE (MAE if outliers shouldn’t dominate) |
| “Multi‑class with rare classes that matter” | Macro‑averaged F1 |
| “Why did the model flag this one transaction?” | SHAP local explanation |
| “Do two groups get flagged at different rates?” | DPPL / DI (post‑training) |
| “Do two groups get different recall?” | RD, recall difference |
| “Bias in labels before training” | CI, DPL (pre‑training) |
| “Detect overfitting or vanishing gradients during training” | Debugger rules (exam name); today TensorBoard / MLflow + CloudWatch |
| “Version models, require sign‑off before deploy” | Model Registry, PendingManualApproval → Approved |
| “Deploy automatically when a model is approved” | EventBridge rule on the approval change |
| “Document intended use, risks and metrics” | SageMaker Model Cards |
| “New model sees real traffic, users see old one” | Shadow test |
| “Score a translation or summary against a reference” | BLEU (translation), ROUGE (summaries), BERTScore (meaning) |
| “Grade LLM answers at scale without people” | LLM‑as‑a‑judge (Bedrock Evaluations) |
| “Check RAG answers stay true to retrieved text” | Faithfulness, Bedrock Knowledge Base evaluation |
Formulas
- Precision TP / (TP + FP)
- Recall (TPR) TP / (TP + FN)
- F1 2PR / (P + R)
- False‑positive rate FP / (FP + TN)
- Specificity TN / (TN + FP)
- Accuracy (TP + TN) / all
- DPPL q̂a − q̂d; DI q̂d / q̂a (1 = parity)
- Expected cost FN × cost_FN + FP × cost_FP
Tuning in one breath
- Built‑in XGBoost tunes on
validation:auc,f1,loglossand others, notaucpr - Its learning rate is
eta - High parallelism makes Bayesian behave like random
- Warm start: up to 5 parents, same objective metric
- Up to 500 training jobs per tuning job, parents included
Governance in one breath
- Registry statuses: PendingManualApproval, Approved, Rejected
- Attach metrics, bias and explainability reports to the model version
- Clarify and Debugger: closed to new customers. Bias metrics with pandas/scikit‑learn, explanations with the SHAP library
- Profiler support ends June 30, 2027
MLA‑C02 tasks this module covers
Mostly Domain 2, ML Model and FM Development (24%).
The module on one page
A trained model is a candidate, not a product. This is the path from candidate to approved version.
Automatic Model Tuning (AMT)
AMT launches many training jobs with different hyperparameters inside ranges you set, watches one objective metric, and reports the best job. Your choices: the strategy, the ranges, the objective, and the budget.
Ranges and scaling
| Range type | Example | Scaling |
|---|---|---|
ContinuousParameter | eta 0.01–0.5 | Logarithmic when the range spans orders of magnitude |
IntegerParameter | max_depth 3–10 | Linear |
CategoricalParameter | optimizer in {adam, sgd} | n/a |
| Values close to 1 | momentum 0.9–0.999 | ReverseLogarithmic |
Why grid search explodes
Values tried per hyperparameter, if each were a grid.
Built‑in XGBoost: what you can tune toward
| Objective metrics | Most influential hyperparameters |
|---|---|
validation:auc, f1, accuracy, error, logloss, rmse, mae, map, ndcg and others. aucpr is not on the list. | alpha, min_child_weight, subsample, eta, num_round |
validation:f1 or validation:auc, then compare finalists on PR‑AUC with your own evaluation step. To tune directly on PR‑AUC, use Script Mode, print the metric, and capture it with a metric_definitions regex.Warm start
| Type | Data and algorithm | Use it to |
|---|---|---|
| IDENTICAL_DATA_AND_ALGORITHM | Must match the parents | Continue a search: more jobs, narrower ranges |
| TRANSFER_LEARNING | Can change (new data, new image version) | Re‑tune on a fresh data snapshot |
Limits: up to 5 parent jobs, all finished; the same objective metric; parameter types can’t change; parents’ jobs count toward the 500‑job cap.
Metrics built from four numbers
Every classification metric comes from the confusion matrix. Type any four counts to see how they move.
Confusion‑matrix calculator
| Metric | Question it answers | Watch out |
|---|---|---|
| Precision | Of the flags, how many were real? | Can be high while missing most positives |
| Recall | Of the real positives, how many did we flag? | Flag everything and it reaches 100% |
| F1 | One number that needs both | Weights precision and recall equally; use F‑beta to favour one |
| ROC‑AUC | How well are positives ranked above negatives, overall? | Flattering when negatives vastly outnumber positives |
| PR‑AUC | Precision across all recall levels | Baseline equals the positive rate (0.005 here), not 0.5 |
| Accuracy | Share of all predictions that were right | Meaningless for rare classes |
The threshold is a business decision
A classifier outputs a score. Where you cut that score decides who gets flagged. 0.5 is just a default; the right cut comes from costs, review capacity or a policy limit.
Threshold explorer
Simulated scores for 100,000 transactions with 500 frauds. Move the threshold and set your costs.
Comparing candidates fairly
Compare models on the same data split and the same evaluation code, then look past the headline metric.
| Check | Why |
|---|---|
| Primary metric on held‑out data (PR‑AUC here) | The number you’ll defend |
| Spread across folds or random seeds | If the spread is bigger than the gap between two models, they’re tied |
| Training vs validation gap | A large gap signals overfitting |
| Metric at your chosen threshold | Two models with equal PR‑AUC can differ where you operate |
| Latency and cost per prediction | Real‑time fraud has a tight time budget |
| Explainability and fairness | Regulated decisions need both |
| Candidate | PR‑AUC (± seeds) | Recall @ 600 alerts | p99 latency | Verdict |
|---|---|---|---|---|
| XGBoost, tuned | 0.71 ± 0.01 | 74% | 8 ms | Ship |
| XGBoost, default | 0.66 ± 0.02 | 69% | 8 ms | Baseline |
| Neural network | 0.70 ± 0.03 | 73% | 21 ms | Tied on quality, slower, harder to explain |
| Linear Learner | 0.55 ± 0.01 | 58% | 3 ms | Too weak |
Illustrative numbers. Log every candidate in MLflow (or SageMaker Experiments, its Studio Classic predecessor) so the table can be regenerated from the runs.
Diagnosing training from its curves
| Debugger rule (exam name) | What it detects | Usual fix |
|---|---|---|
| LossNotDecreasing | Loss flat or stuck | Check learning rate and data |
| Overfit | Validation worsens while training improves | Early stopping, regularization |
| Overtraining | Training continues long after the best point | Early stopping |
| VanishingGradient / ExplodingTensor | Gradients near zero, or values blow up | Activations, initialization, gradient clipping, lower LR |
| ClassImbalance | Skewed labels during training | Weights, resampling |
Explaining what the model learned
| XGBoost importance type | Measures | Watch out |
|---|---|---|
| gain | Average loss reduction when a feature is used | The most useful default |
| cover | How many rows the feature’s splits affect | Breadth, not strength |
| weight | How often the feature is used to split | Favors features with many distinct values |
Built‑in importance is global and has no direction. SHAP values explain single predictions: each feature pushes the score up or down from a baseline, and the pushes add up to the prediction.
Post‑training fairness
Pre‑training metrics (Module 2) look at the labels. Post‑training metrics look at the model’s predictions by group. First decide the favorable outcome: here, not being flagged.
| Metric | Compares across groups |
|---|---|
| DPPL | Share predicted positive (difference) |
| DI Disparate impact | Share predicted positive (ratio); 1 = parity, and many teams investigate below 0.8 |
| RD Recall difference | True‑positive rate |
| AD Accuracy difference | Accuracy |
| DAR Difference in acceptance rates | Precision |
| SD Specificity difference | True‑negative rate |
| TE Treatment equality | Ratio of false positives to false negatives |
| CDDPL, FT, GE | Disparity within subgroups, counterfactual fliptest, generalized entropy |
DPPL, DI and recall gap
Model Registry and approval
- Register with the SDK (
model.register(...)) orCreateModelPackage; a pipeline step can register automatically. - Attach the evaluation report through
ModelMetricsso the reviewer sees numbers, not a promise. - Approval can be manual, or automated in a pipeline when metrics clear a bar; either way, the status change is what deployment listens for.
- Share model versions across accounts (for example, dev to prod) with resource policies.
Is the model worth running?
Price the outcomes at your chosen threshold. Example: 300 fraud attempts a day averaging $180, 80% caught, 2,000 false alarms a day at $1.50 of friction each, and $4,000 a month for training, hosting and monitoring.
Hands‑on project: decide like an engineer
Three situations you will meet when tuning and evaluating for real. Pick an answer, then open the reasoning.
1. A Bayesian search that didn’t learn
A tuning job uses the Bayesian strategy with max_jobs=24 and max_parallel_jobs=24. The results look no better than random.
- Raise max_jobs to 200
- Lower max_parallel_jobs (for example to 3–4), or switch to random search on purpose
- Switch to grid search
Suggested answer
2. The objective metric that doesn’t exist
A tuning job on the built‑in XGBoost sets objective_metric_name='validation:aucpr' and fails immediately.
- Rename it to validation:pr_auc
- Tune on validation:f1 or validation:auc and compare finalists on PR‑AUC yourself, or use Script Mode and emit PR‑AUC with a metric_definitions regex
- Remove the objective metric
Suggested answer
aucpr. Script Mode lets you print any metric and capture it from the logs.3. More alerts than people
At the default 0.5 threshold the model raises 2,300 alerts a day. The review team can handle 600.
- Hire more reviewers before launch
- Set the threshold so about 600 transactions a day score above it, and report precision and recall at that point
- Keep 0.5 and review a random 600
Suggested answer
The build, step by step
- Tune the Module 3 XGBoost with AMT: Bayesian, 30 jobs, 3 in parallel, objective
validation:f1,etaon a log scale, early stopping Auto. - Evaluate the top 3 on the untouched test set: PR‑AUC, plus precision and recall at several thresholds.
- Pick the threshold twice, by cost and by a 600‑alert capacity, and compare the two.
- Explain with SHAP: a global summary and three individual flagged transactions.
- Check fairness with pandas: DPPL, DI and recall gap across age bands at the chosen threshold.
- Register the winner with its metrics and reports as PendingManualApproval, and write a Model Card.
- Approve it and confirm an EventBridge rule sees the status change.
- Is the winner really better? Retrain the top two configurations with three random seeds each. If the seed‑to‑seed spread is larger than the gap between them, call it a tie and pick on latency and explainability.
The rest of the exam guide for this module
Every skill MLA‑C02 lists for Task 2.3, plus related skills from 2.2 and 3.3, where each is covered, then a short lesson for each one the sections above don’t fully reach.
| Skill in the exam guide | Where |
|---|---|
| 2.2.3 Hyperparameter optimization (AMT) | Section 2 |
| 2.3.1 Reproducible experiments (MLflow, Bedrock evaluations, Prompt Management) | Section 5, Module 3, deep dive 6 |
| 2.3.2 Performance baselines and drift detection | Deep dive 2 |
| 2.3.3 Shadow variants vs production variants | Deep dive 3 |
| 2.3.4 Explain model outputs | Section 7 |
| 2.3.5 Debug convergence | Section 6 |
| 2.3.6 Evaluation for traditional ML and GenAI | Sections 3–4, deep dives 1 and 4 |
| 2.3.7 Human evaluation, human‑in‑the‑loop | Deep dive 5 |
| 2.3.8 BLEU, ROUGE, BERTScore, semantic similarity | Deep dive 4 |
| 2.3.9 AI evaluation, bias detection, LLM‑as‑a‑judge | Section 8, deep dive 6 |
| 2.3.10 RAG monitoring and retrieval accuracy | Deep dive 7 |
| 3.3.6 Model versions (Model Registry, MLflow) | Section 9 |
Deep dive 1: regression and multi‑class metrics
| Metric | Meaning | Use when |
|---|---|---|
| MAE | Average absolute error | Errors should count linearly; outliers shouldn’t dominate |
| RMSE | Square root of average squared error | Big errors are much worse than small ones |
| R² | Share of variance explained | Comparing to predicting the mean |
| MAPE | Average percentage error | Scale‑free reporting; breaks near zero |
| Macro F1 | Average of per‑class F1 | Every class matters equally, including rare ones |
| Micro / weighted F1 | Pooled, or weighted by class size | Overall performance dominated by big classes |
Deep dive 2: baselines and drift
- Baselines to beat: the current production model, a simple rule (“flag above $2,000 at night”), and a simple model. A new model must beat all three on the same data.
- Monitoring baseline: statistics of the training data (and of the model’s quality) captured before launch, so live data can be compared with it. SageMaker Model Monitor creates these baselines and schedules the comparisons.
- Data drift: inputs change (new merchants, new devices). Concept drift: the link between inputs and labels changes (fraudsters change tactics). Detect data drift with distribution tests such as KS or PSI; concept drift needs fresh labels.
Deep dive 3: shadow tests vs A/B tests
Deep dive 4: metrics for generated text
| Metric | Compares | Typical use |
|---|---|---|
| BLEU | n‑gram precision against reference text | Machine translation |
| ROUGE (‑1, ‑2, ‑L) | n‑gram and longest‑sequence recall against a reference | Summarization |
| BERTScore | Similarity of contextual embeddings | Paraphrases: same meaning, different words |
| Semantic similarity | Cosine similarity of sentence embeddings | Answer matches the reference in meaning |
| Perplexity | How surprised a model is by text | Language‑model fit, not answer quality |
| Exact match / F1 | Token overlap with a short answer | Extractive question answering |
Reference‑based scores reward word overlap, so a correct answer worded differently can score low. Pair them with meaning‑based scores, a judge model or people.
Deep dive 5: people in the loop
- Bedrock model evaluation with human workers: your team or AWS‑managed reviewers rate or compare model outputs.
- Amazon Augmented AI (A2I): sends low‑confidence predictions to human reviewers in production.
- SageMaker Ground Truth: labeling and rating jobs for building evaluation sets.
- Give reviewers a rubric and measure agreement between them; disagreement means the rubric is unclear.
Deep dive 6: evaluating foundation models
| Approach | Strength | Weakness |
|---|---|---|
| Automatic metrics (programmatic) | Cheap, repeatable | Misses meaning and tone |
| LLM‑as‑a‑judge | Scales; grades correctness, helpfulness, harmfulness | Judge can be biased; spot‑check with people |
| Human evaluation | Best for nuance and brand fit | Slow and costly |
On AWS: Amazon Bedrock Evaluations (automatic, LLM‑as‑a‑judge and human jobs), the open‑source fmeval library for SageMaker‑hosted models, and Bedrock Prompt Management to version the prompts you evaluate. Responsible‑AI checks (toxicity, harmfulness, bias, refusals) belong in the same evaluation set.
Deep dive 7: evaluating and monitoring RAG
Self‑check questions
Answer each one aloud first, then open it to check.
1. How does Bayesian tuning differ from random and grid search, and when is each better?
Bayesian search models how hyperparameters relate to the objective and picks each new trial from finished results, so it needs fewer jobs but runs more sequentially. Random search samples independently, so it parallelizes fully. Grid search tries every combination of categorical values and only suits small spaces. Hyperband suits iterative training that reports metrics per epoch, stopping weak trials early.
2. Why can’t you rely on accuracy for fraud, and what replaces it?
With 0.5% fraud, predicting “legit” for everything scores 99.5% accuracy and catches nothing, because true negatives dominate the formula. Use precision, recall, F1 and PR‑AUC, and always look at the confusion matrix at your chosen threshold.
3. What do you give up when you raise the threshold?
Fewer transactions get flagged, so precision usually rises and false alarms fall, but more fraud slips through, so recall drops. Lowering it does the reverse. Where to sit depends on the cost of a missed fraud versus a false alarm, and on how many alerts people can review.
4. Name three ways to choose a threshold.
- Minimize expected cost: FN × cost of a miss + FP × cost of a false alarm.
- Fit review capacity: flag the top N scores a day.
- Meet a target: a minimum precision, or a maximum false‑positive rate, then maximize recall within it.
5. When would you use warm start, and which type?
To continue a search with more jobs or narrower ranges on the same data and algorithm, use IDENTICAL_DATA_AND_ALGORITHM. To re‑tune after the data or algorithm version changes, use TRANSFER_LEARNING. Both need the same objective metric and allow up to 5 finished parent jobs.
6. How do feature importance and SHAP differ?
Built‑in importance (gain, cover, weight) ranks features globally with no direction. SHAP assigns each feature a signed contribution for each prediction, so you can explain one decision and, by averaging, get a global view with direction.
7. What do DPPL and DI measure, and how do they relate?
Both compare how often each group receives positive predictions. DPPL is the difference between the groups’ rates; DI is the ratio of the disadvantaged group’s rate to the advantaged group’s. DPPL = 0 and DI = 1 both mean demographic parity. Pair them with recall difference, since equal flag rates can still hide unequal error rates.
8. How does a model move from registered to deployed?
It’s registered as a version in a model package group with its artifact, image, metrics and reports, status PendingManualApproval. A reviewer or an automated check sets it to Approved or Rejected. An EventBridge rule on the approval change starts the deployment pipeline. Earlier Approved versions stay available for rollback.
9. How do you tell if two candidate models are really different?
Evaluate both on the same held‑out data with the same code, repeat across folds or random seeds, and compare the gap with the spread. If the spread is larger, they’re tied; decide on latency, cost, explainability and fairness.
10. How would you evaluate a RAG assistant?
Split it: score retrieval (are the right passages found? context relevance and coverage, recall@k) and generation (is the answer correct, complete and faithful to the retrieved text, with accurate citations?). Use a labeled question set, an LLM judge with human spot checks, and keep running it after launch.
How to read an exam question
The answer hides in a few words: who does the work, how fast, how much effort, what must not happen. Find those, then eliminate.
Walkthrough 1. A deep‑learning model reports validation loss every epoch. The tuning budget is tight, so the team wants to stop poor trials early and give more training to promising ones. Which tuning strategy should they use?
- Grid search
- Random search with 200 training jobs
- Bayesian search with every job running in parallel
- Hyperband, with the tuner’s own early stopping turned off
Show the reasoning
Walkthrough 2. A missed fraud costs $200 and a false alarm costs $3 in customer friction. The model outputs a fraud probability. How should the team choose the decision threshold?
- Keep the default of 0.5
- Pick the threshold with the highest accuracy
- On validation data, pick the threshold that minimizes 200 × missed frauds + 3 × false alarms
- Pick the threshold with the highest F1
Show the reasoning
Walkthrough 3. A new model must be tried on real production traffic to compare latency and outputs with the current model, with no effect on any customer. What should the team do?
- An A/B test sending 10% of traffic to the new model
- A canary release to 5% of traffic
- A shadow test: the new model gets a copy of requests and its answers are only logged
- A batch transform on last month’s data
Show the reasoning
Flashcards
Say the answer out loud before you reveal it. “Again” puts the card back in the round; “Got it” retires it. Progress is saved in this browser.
Practice test
Common traps and outdated advice
Mistakes that show up often in tutorials and sample code, with the fix.
- The built‑in XGBoost’s tunable metrics don’t include
aucpr. Tune onvalidation:f1orvalidation:auc, or emit PR‑AUC from Script Mode. - The built‑in XGBoost calls its learning rate
eta; ranges keyedlearning_ratebelong to other frameworks. - Recommending a log scale for the learning rate means setting
scaling_type='Logarithmic'; a plain continuous range samples linearly and wastes trials at the top of the range. - Running Bayesian search with parallelism equal to the job count turns it into random search.
- “Bayesian always wins” is too strong: random search is better when you need full parallelism, and Hyperband beats both for iterative training.
- Review capacity sets alert volume, not a precision target. If people can review 600 a day, flag the top 600 and then read off precision and recall.
- Equal or low feature importance for a protected attribute doesn’t show fairness; proxies carry the same information. Measure outcomes by group.
- SageMaker Clarify and SageMaker Debugger are closed to new customers; existing users keep them. The exam may still name both, so know what they do and their replacements.
- SageMaker Profiler support ends June 30, 2027. Use the framework profiler with TensorBoard, and CloudWatch.
- Report metrics from code, on a test set the model never saw during tuning; tuning on the test set quietly turns it into a validation set.
- SageMaker Experiments is the Studio Classic tool; managed MLflow is the current one. The concepts map one to one.