smartyfy.mrindigi.com

AI Foundations for Students | 017. Overfitting, Generalization and Baselines

AI Foundations for Students · Lesson 17 of 36

Module 3: Machine Learning on Paper

In this lesson

Learning goal: Compare a memorizing model with a simple baseline on new examples.

A perfect practice score can mislead

A model can fit the examples it has seen very closely yet perform poorly on new examples. Overfitting describes this problem of fitting training-specific details that do not transfer well. Generalization is the ability to perform usefully on new relevant examples. Neither idea means that training performance is unimportant; rather, training success must be compared with evidence beyond the training set.

Imagine a paper sorter that memorizes every training card ID and its label. It can repeat those labels perfectly. When an unfamiliar ID appears, the lookup table has no entry. If it defaults to the most common label, its new-case behavior may be no better than a very simple method. A complicated memory of old answers can create an impressive demonstration without solving the intended new-card task.

A fully specified comparison

Training cards are A: width 6 cm, small; B: 8 cm, small; C: 12 cm, large; D: 14 cm, large. Model M memorizes the four IDs and labels, then predicts small for every unseen ID. Model W predicts small for widths below 10 cm and large otherwise. Baseline S always predicts small, ignoring width and ID.

The new evaluation cards are E: 7 cm, small; F: 11 cm, large; G: 13 cm, large; H: 9 cm, small. These are fictional examples supplied for a worked comparison. Both M and W get all four training cards correct. Baseline S gets the two small training cards correct, so its training score is two out of four.

Evaluate the new cases

On E, F, G and H, Model M predicts small four times because every ID is unseen. It gets E and H correct and F and G wrong: two out of four, or 50%. Baseline S makes exactly the same predictions and has the same new-case score. Model W uses widths and gets all four new labels correct: four out of four.

These results show that Model M’s perfect training score did not provide useful improvement over the simple baseline on this test. Model W performs better here because the evaluation labels follow the same width boundary. Four fictional examples do not prove W will handle measurement errors, new materials or a changed category definition. Keep the claim as small as the evidence.

Baselines ask whether complexity helps

A baseline is a deliberately simple comparison method. It might always choose the most frequent training label or use an obvious rule. It should be defined before evaluating the new cases and use only information legitimately available. A baseline is not meant to win every task; it tells us how much additional value a more complex method provides.

If nine out of ten cards are small, always predicting small gets 90% accuracy while missing every large card. That can be unacceptable if large cards need special handling. The apparently high score reflects the category balance. Later we will inspect errors separately using a confusion matrix. Always ask which categories exist, how common they are and which mistakes matter.

Improve the evidence, not just the score

To investigate poor generalization, examine whether the features relate to the task, whether the sample covers relevant cases and whether the evaluation is independent. More complexity is not an automatic solution. A simpler model with a relevant feature may transfer better. More examples can help if they add missing variety; duplicating known cases mainly enlarges the file.

Do not remove difficult new cases merely to improve reported accuracy. Instead, record the failure and propose a change that could address it. A model that declines uncertain cases also needs coverage reporting, because accuracy on the answered subset alone can hide how often it cannot help. For a student project, an honest limited result is more valuable than a perfect score built from selective examples.

Worked practice

Worked exercise 1: Compare training and new-case scores

Task: Calculate training and new-case accuracy for Model M from the supplied comparison. Explain the difference.

Worked solution: Training accuracy is 4/4 = 100% because the memorized IDs are present. New-case accuracy is 2/4 = 50% because all new IDs receive the default small label. The change reveals that memorizing the practice examples did not capture the width relationship needed for these new cards. It is a worked illustration of poor generalization.

Worked exercise 2: Check the baseline honestly

Task: A test pack has nine small cards and one large card. Baseline S always predicts small. What are its accuracy and large-card success?

Worked solution: It correctly predicts nine of ten cards, giving 90% overall accuracy. It correctly identifies zero of the one large card, so its large-card recall is 0/1 = 0%. The high overall percentage hides complete failure on the minority category. Whether that is acceptable depends on the task, not the score alone.

Worked exercise 3: Select a useful next example

Task: You can add either ten copies of a known 6 cm card or new fictional cards near 10 cm. Which better investigates the width boundary?

Worked solution: Add distinct cases near the boundary, such as 9.8, 10.0 and 10.2 cm with reference labels from the policy. They test whether the comparison and measurement handling work where the decision changes. Ten copies of 6 cm contribute little new boundary evidence. Keep a separate held-out set if using these new cases to revise the model.

Check your understanding

MCQ 1: Which result most suggests overfitting?

  1. Strong training results with much weaker relevant new-case results
  2. Good results on both training and relevant new cases
  3. A simple model with a documented rule
  4. A low training score alone
Check the answer and explanation

Answer: A. A gap between fitting known examples and handling new ones is the key warning.

MCQ 2: How many new cases does Model M classify correctly?

  1. One
  2. Two
  3. Three
  4. Four
Check the answer and explanation

Answer: B. It predicts small for every unseen ID, matching E and H only.

MCQ 3: What is the purpose of a baseline?

  1. Select a complex model before measuring its performance
  2. Provide a simple reference for added value
  3. Replace final testing with an easily understood rule
  4. Provide a lower score by design so improvement looks larger
Check the answer and explanation

Answer: B. It makes improvement claims meaningful by providing a defined comparison.

MCQ 4: What does 90% accuracy hide in the nine-small example?

  1. Every small card was wrong
  2. No examples were evaluated
  3. The one large card was missed
  4. The denominator was nine
Check the answer and explanation

Answer: C. A majority-label strategy succeeds on the frequent category and misses the minority.

MCQ 5: Which change adds useful boundary evidence?

  1. Repeat the same easy card
  2. Delete the error cases
  3. Use IDs as labels
  4. Add new cases just below, at and above the threshold
Check the answer and explanation

Answer: D. Those cases test the region where the rule changes category.

Sources and further reading