Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 42

The Importance of Independent Test Sets and Detecting Data Leakage

Recommended resources

Introduction

Welcome back! In our previous lesson, we focused on the critical importance of "ground truth"—the expert-labeled data that serves as the answer key for training an AI. We learned how to evaluate the quality of these labels by looking at who created them, how many experts were involved, and how disagreements were resolved.

Today, we'll address the next crucial step: how this labeled data is divided and used to build and test a model. It’s not enough to have a high-quality dataset; you must use it in a structured way to get a true picture of the AI's capabilities. If you test a student on the exact same questions they used for homework, you're not measuring their ability to generalize their knowledge, but rather their ability to memorize. The same principle applies to AI.

This lesson directly addresses the learning outcome: Explain the importance of using an independent test set and identify potential data leakage in a study design. We will explore why data is split into training, validation, and testing sets, and how a critical error called "data leakage" can create a dangerous illusion of high performance.


The Three Datasets: Training, Validation, and Testing

To build a reliable AI model, researchers split their master dataset into three distinct parts, each with a specific job. The analogy of a student preparing for a national competition is a helpful way to understand their roles.

To introduce these concepts, please watch the following video.

Validation data: How it works and why you need it - Machine Learning Basics Explained

This video from Galaxy Inferno Codes uses a clear teacher-student analogy to explain the purpose of the training, validation, and test datasets in machine learning.

Please watch from the beginning until 04:47. As you watch, focus on understanding the distinct purpose of each of the three data splits.

As the video explained, the three datasets serve unique functions:

  1. Training Set (The Homework): This is the largest portion of the data. The AI model uses these examples (e.g., thousands of radiographs with labeled caries) to learn the patterns. It's like a student studying questions and answers from last year's competition.
  2. Validation Set (The Practice Quiz): After initial training, the developers need to fine-tune the model and compare different versions of it. They use the validation set for this. It contains data the model hasn't seen during training. This is like giving the student a new set of practice questions to see if they've truly understood the material or just memorized the homework. Based on the results, the teacher (developer) picks the best student (model) to send to the competition.
  3. Test Set (The Final Exam): This is a completely separate, "quarantined" set of data. It is used only once, at the very end of the development process, to get a final, unbiased assessment of the chosen model's performance on brand new, unseen data. This predicts how the model will perform in the real world. Crucially, the results from this test are only for evaluation; you are not supposed to go back and tweak the model based on the test results.

The American Dental Association (ADA) emphasizes the importance of this process. Let's look at their formal definitions.

[PDF] Artificial and Augmented Intelligence: Uses in Dentistry

The ADA's white paper on AI provides clear, official definitions for these datasets. Reading them will help solidify your understanding in a professional context.

Please read the definitions for Training Dataset, Validation Dataset, and Testing Dataset. You can find them in the 'Terms and Definitions' section near the beginning of the document.

The key takeaway is that the test set must be independent. It acts as the final, honest judge of the model's ability to generalize its knowledge to new cases, just as a final exam tests a student's ability to apply concepts to new problems.


Data Leakage: When the "Final Exam" is Compromised

What happens if this strict separation is violated? The result is a critical flaw known as data leakage.

Data leakage occurs when information from outside the training dataset (most often from the validation or test set) is used to create the model. This leads to an overly optimistic estimation of the model's performance, because the model has essentially been given some of the answers to the test ahead of time.

Let's watch a short video from StatQuest that explains this concept with clear examples.

Live 2020-01-20!!! Favorite ML, Data Leakage, How to Learn ML

Josh Starmer from StatQuest provides an intuitive explanation of data leakage, starting with a simple case and moving to a more subtle, common example.

Please watch the segment from 05:01 to 08:27. Pay attention to both the obvious and the 'sneaky' examples of data leakage.

The video highlights two ways leakage can happen:

  1. Obvious Leakage: Using the same data for training and testing.
  2. Subtle Leakage: Performing a data preparation step (like imputing missing values) on the entire dataset before splitting it. Information from the test set is used to inform the training set, breaking their independence.
Data Leakage through Mean Imputation
This diagram visually represents the 'sneaky' leakage discussed in the video. When a preprocessing step like mean imputation is applied to the whole dataset, information from the test set (its values contribute to the mean) 'leaks' into the training set. This gives the model an unfair advantage and results in an inflated accuracy score.

Data Leakage in Dental Imaging

In medical and dental imaging, one of the most common and deceptive forms of data leakage is failing to split the data at the patient level.

Imagine you are building an AI to detect caries from a dataset of bitewing radiographs from 100 patients, with each patient having multiple images.

  • Incorrect (Leaky) Method: Randomly shuffle all the images and split them into training and test sets. With this method, it's almost certain that images from the same patient will end up in both the training and test sets.
  • Why it's a problem: The AI model might not learn to identify caries. Instead, it might learn to recognize the unique anatomical features of Patient X's teeth or even the specific artifacts from the sensor used on Patient X. When it sees another image of Patient X in the test set, it easily classifies it correctly because it has "memorized the patient," not because it understands the pathology.
  • Correct (Subject-Wise) Method: First, divide the 100 patients into groups (e.g., 80 for training, 20 for testing). Then, all images from the first 80 patients go into the training set, and all images from the remaining 20 patients go into the test set. This ensures the test set contains patients the model has never seen before, providing a true test of generalization.

The Real-World Impact and How to Spot It

This isn't just a theoretical concern. Data leakage is a widespread problem in AI research that leads to studies reporting wildly inflated performance. A fascinating scoping review on AI for Alzheimer's disease diagnosis uncovered just how significant this issue is.

Data Leakage in Deep Learning for Alzheimer's Disease Diagnosis

This research paper, 'Data Leakage in Deep Learning for Alzheimer's Disease Diagnosis,' investigates how methodological flaws inflate AI performance. Its findings are a powerful lesson for any clinical field, including dentistry.

This is a dense paper, so we'll focus only on the key takeaways: Read the section '1.2. The Problem of Data Leakage' to understand the definition and its clinical stakes. Skim the 'Risk Stratification Framework' (Section 2.6) to see how they categorized studies based on their risk of leakage (Low, Moderate, High). Read the first paragraph of the Results section '3.2. The Evidence for Data Leakage'. Note the reported accuracy for each risk group. Finally, read the first paragraph of the Discussion (Section 4). This part contains the most powerful finding about the drop in accuracy when leakage was fixed. Focus on the relationship between leakage risk and reported accuracy.

The findings from this paper are staggering and directly relevant to our lesson:

  • Inflated Performance: Studies with a high risk of data leakage (e.g., not using subject-wise splitting) reported near-perfect accuracies of 95-99%.
  • Realistic Performance: Studies with low risk (which correctly used subject-wise data splitting) reported much more realistic accuracies of 66-90%.
  • The Smoking Gun: One study cited in the review re-analyzed its data. Using a leaky "slice-wise" split, it got 94% accuracy. When they corrected the method to a proper "subject-wise" split, the accuracy of the exact same model plummeted to 66%. This 28-point drop was caused only by fixing the data leakage.

This demonstrates that when you read a dental AI paper claiming near-perfect results, your first reaction should be skepticism, and your first question should be: How did they split their training and test data?

The ADA's white paper (LINK), in its appendix for clinicians, even includes the direct question: "Was the validation dataset sequestered from the training and testing processes?" This highlights that verifying data independence is a core responsibility of the clinical user.


Conclusion

In this lesson, we've unraveled the crucial process of data partitioning for AI model development. You've learned that building a trustworthy model isn't just about having good data; it's about using that data with strict discipline.

Key Takeaways:

  • AI datasets are split into training (for learning), validation (for tuning), and testing (for final, unbiased evaluation).
  • An independent test set is like a final exam—it must contain data the model has never seen before to provide a true measure of its real-world performance.
  • Data leakage is a critical flaw where information from the test set contaminates the training process, leading to falsely inflated performance metrics.
  • In dental imaging, a common form of leakage is failing to split data at the patient level (subject-wise splitting).
  • When you encounter a study with exceptionally high accuracy, you should immediately investigate its methodology for data splitting to check for potential leakage.

Preview of the Next Lesson

We have now completed our look at the foundational steps of creating a dental AI model: from collecting data, to establishing ground truth, to correctly partitioning the data for training and testing. Now, we're ready to move to the user-facing side. In our next lesson, we will learn to interpret common AI output formats: probability scores, bounding boxes, and segmentation masks. This will bridge the gap between how a model is built and how you, as a clinician, will interact with its results.