Responsible AI, security and governance · 13 min
Bias, variance and responsible datasets
In this lesson you will learn to tell high bias from high variance, which four characteristics the exam guide asks of a dataset and how to detect that a model treats a group of people worse.
In domain 4 of the AWS Certified AI Practitioner exam, the word bias has two meanings, and the exam uses both. Statistical bias is how far from the correct answer a model's predictions fall. Fairness bias, on the other hand, appears when a model treats a group of people worse, and it often originates in the data the model was trained on. For example, a bank model that miscalculates how much any customer earns has statistical bias, and one that rejects more loans for young customers for no reason has fairness bias.
What are bias and variance?

Bias and variance describe two different ways in which a model gets things wrong. Bias is how far from the correct answer the predictions fall on average, and variance is how spread out they are from one another, that is, how much they change from one attempt to the next. That is why a model with high bias and low variance is always wrong in the same way, while one with low bias and high variance gives predictions that surround the correct answer, but scattered. For example, if a bank model calculates that every customer spends a thousand dollars less than they really do, it has high bias and low variance; if it sometimes calculates too much and sometimes too little, with large errors, it has high variance.
What you are looking for is a model with low bias and low variance, whose predictions stay together and close to the correct answer. The worst case is the opposite, with high bias and high variance, where the predictions are both far away and scattered. For example, the model you are looking for calculates each customer's spending almost exactly, and the worst one is very wrong and wrong in a different way each time.
Underfitting and overfitting
A model is trained with one group of data, called training data, and then tested with another group it has never seen, called test data. AWS relates bias and variance to how well the model fits that data:
- Underfitting, which corresponds to high bias and appears when the model gives poor results on the training data and also on the test data. It is usually a very simple or undertrained model, and it is fixed by training longer (more epochs) or by adding features. For example, a model that tries to know whether a customer will pay back their loan by looking only at their age fails with every customer, because it lacks information.
- Overfitting, which corresponds to high variance and appears when the model works well on the training data and poorly on new data, because it memorized the examples instead of learning the pattern. It usually comes from too little data or data with a lot of noise, and it is fixed with more data, with regularization or by stopping training earlier. For example, a model trained with only one hundred customers can get all of them right and fail with the new customers who come to the bank.
High bias or high variance?
0 of 4Tap the column that matches each model.
98% accuracy in training and 70% in testing
61% in training and 60% in testing
It is fixed with more data or with regularization
It is fixed by training more epochs or adding features
When the two meanings come together
AWS has an example where statistical bias comes from a problem in the data. A model predicts whether a student will graduate and was trained only on data from a private university with high-income students. At that university the model works, but with students from public universities its accuracy drops, because that profile wasn't in the data. For example, the model may fail more often with a student who works while studying, because it never saw a case like that.
What does the guide ask of a dataset?

A dataset is the collection of examples a model is trained with. To avoid problems like the university one, task 4.1 of the exam guide names four characteristics that dataset must have, and here the word "characteristic" means a quality of the data:
- Inclusive, which means that it represents the people who will use the system. For example, if the bank serves customers of all ages, the data includes customers of all ages.
- Diverse, which means that it has a variety of cases, contexts and ways of asking. For example, a bank chat is trained with formal questions, informal ones and ones with spelling mistakes.
- Curated, which means that it comes from reviewed sources and that whatever doesn't fit the use case was removed. For example, the test messages the programmers wrote are removed.
- Balanced, which means that it has enough examples of each group to be able to measure whether the model is fair to all of them. For example, there aren't thousands of customers from one age group and only a few from another.
The Responsible AI Lens adds that you should document what was included in the dataset and what was left out. To balance it, it proposes collecting more data from the groups with few examples or using stratified sampling. For example, if the bank has few young customers in its data, it can look for more cases from that group before training.
A lack of diversity shows up in another AWS example, that of a model that recognizes dogs and was trained almost only on photos of dogs in parks. That model can learn that grass means dog, and then it doesn't recognize a dog inside a house. For example, a photo app with that model wouldn't tag as a dog the photo of a pet asleep on the couch.
Match each problem with the missing characteristic
0 of 4 pairsTap a problem and then the dataset characteristic that prevents it.
0 of 4 pairs.
How do you detect bias in a model?

Task 4.1 also gives three example tools for detecting fairness bias:
- Label quality, which matters because a model that learns from data labeled by people inherits their errors and their prejudices. A label is the correct answer a person puts on each example, such as marking a past loan as "paid" or "not paid".
- Human audits, where people review a sample of what the model decides, especially where an error has consequences. For example, a bank employee reviews some of the loans the model rejected every week.
- Subgroup analysis, which measures the model in each group in addition to the average. For example, you measure how often it is right with young customers and how often with older ones.
Label quality
To review label quality, the Lens recommends measuring how much the labelers, who are the people who put the labels on, agree with one another. It also recommends adding examples with a known answer, to find anyone who doesn't follow the rules, and checking whether someone labels certain groups differently. For example, if two labelers mark the same loan application differently, the rules they follow need to be reviewed, and if one marks almost every customer from one neighborhood as "risky", they may be bringing in a prejudice.
Subgroup analysis
Subgroup analysis is needed because a high average can hide a group the model does poorly on. For example, a credit model that is right 92% of the time can be right much less often with customers aged 18 to 25, because that group was small in the data and barely moved the average.

With example figures, the 92% average can hide that the model is right 71% of the time with the 18 to 25 group. To find differences like that, the Lens recommends measuring each group with the same metrics and comparing the differences against a limit agreed on beforehand. Those metrics are accuracy, which is the percentage of correct answers, precision and recall. It also recommends testing with pairs of inputs that differ only in one demographic detail, such as age or sex, to see whether the response changes. For example, the bank gives the model two identical applications in which only the age changes, and if one is approved and the other isn't, the model is using age unfairly.
What do you do first?
A model that approves loans has 92% accuracy, but there are complaints that it rejects young customers. What tells you whether the complaints are right?
Amazon SageMaker Clarify
Amazon SageMaker Clarify was the AWS tool that calculated bias metrics, and it may appear in a course or in an old question. Today it no longer accepts new customers, and the current version of the exam guide doesn't name it. For example, if an old question offers you Clarify to measure the bias of a credit model, recognize that this was its job, even though a new customer can no longer turn it on today.
The analysis in both accounts
If you want to do a subgroup analysis yourself, AWS suggests calculating the metrics with libraries such as pandas and scikit-learn, which you can run on your computer or in Amazon SageMaker AI. That service is available on the free plan of the new experience and in the full account. For example, with pandas you can split a customer table by age group and count how many correct answers the model had in each group.
On the exam
Questions on this topic usually give two accuracy figures or describe a group with worse results. These clues point to the answer:
- A model that does well in training and poorly in testing, which indicates high variance.
- A model that fails in training and in testing, which indicates high bias.
- "A demographic group gets worse results", which points to subgroup analysis and to balancing the data.
- "Labelers who don't agree", which points to label quality.
- "Represents all users", which points to an inclusive dataset.
For example, if the question says a model is almost always right in training and much less often in testing, the gap between the two figures tells you it is high variance.
Review question
A team trains a model to detect fraud. It is right 97% of the time on the training data and 68% of the time on new transactions. What best describes the problem and how is it fixed?
Next
- Responsible AI Lens - AWS Well-Architected Framework, in its dataset planning and release criteria areas.
- Take an AI Practitioner practice exam at /examenes and review your result in domain 4.