2.3.1. Detecting and Mitigating Bias in Training Data
š” First Principle: Bias in ML starts with biased data, not biased algorithms. An algorithm trained on unbiased data produces fair results; the same algorithm trained on biased data produces biased results. The exam tests your ability to detect pre-training bias using specific metrics and mitigate it using specific techniques.
Pre-Training Bias Metrics (SageMaker Clarify):
| Metric | What It Measures | Example | Concern If |
|---|---|---|---|
| Class Imbalance (CI) | Proportion difference between facet values | 80% male, 20% female in training data | CI far from 0 |
| Difference in Proportions of Labels (DPL) | Whether positive labels are distributed equally across facets | 60% of males labeled "hire," 30% of females | DPL far from 0 |
| KL Divergence | How much one distribution diverges from another | Feature distributions differ significantly between groups | Large divergence values |
| Jensen-Shannon Divergence | Symmetric version of KL divergence | Comparing label distributions between groups | Large divergence values |
Mitigation Techniques:
| Technique | How It Works | When to Use | AWS Tool |
|---|---|---|---|
| Random oversampling | Duplicate minority class samples | Moderate imbalance, sufficient data | Data Wrangler built-in |
| Random undersampling | Remove majority class samples | Large dataset, extreme imbalance | Data Wrangler built-in |
| SMOTE | Generate synthetic minority samples | Moderate imbalance, tabular data | Data Wrangler SMOTE transform |
| Stratified sampling | Maintain class proportions during splitting | All cases (should be default) | SageMaker Processing |
| Reweighting | Assign higher weights to minority class | When resampling is impractical | Algorithm-level (class_weight parameter) |
ā ļø Exam Trap: SageMaker Clarify is used for both pre-training bias detection (data analysis) and post-training bias detection (model predictions). When the question asks about bias before training, the relevant metrics are data-level metrics like CI and DPL. When the question asks about bias after training, the relevant metrics are model-level like Disparate Impact and Conditional Demographic Disparity. Don't mix the two contexts.
Reflection Question: A loan approval dataset has 70% applications from urban areas and 30% from rural areas. The approval rate is 65% for urban and 40% for rural. Which bias metrics would flag this, and what mitigation would you recommend?