Handling Class Imbalance in Machine Learning
A healthcare startup is developing a deep learning model to detect diabetic retinopathy from retinal fundus images. The dataset contains 50,000 images, but only 5% are labeled as positive for the disease. The team uses a convolutional neural network (CNN) with a final sigmoid layer and binary cross-entropy loss. After training for 20 epochs, the model achieves 95% accuracy on the test set, but the recall for the positive class is only 10%. The team suspects the model is biased toward the negative class due to class imbalance. The data is stored in a secure environment, and no additional labeled data can be obtained. The team has access to the following techniques: oversampling the minority class, undersampling the majority class, using class weights in the loss function, applying data augmentation, and using a different architecture. Which course of action is most likely to improve recall for the positive class while maintaining reasonable overall performance?
Quick Answer
The answer is assigning higher class weights to the positive class in the loss function. This technique directly increases the penalty for misclassifying the minority positive samples during backpropagation, forcing the CNN to learn more discriminative features for diabetic retinopathy without altering the original dataset distribution—a critical constraint when no additional labeled data can be obtained. On the CompTIA AI+ AI0-001 exam, this scenario tests your understanding that class imbalance handling techniques like weighting preserve the natural data distribution while improving recall, unlike oversampling or undersampling which risk overfitting or information loss. A common trap is assuming data augmentation alone solves imbalance, but it does not address the gradient dominance of the majority class. For the exam, remember: weights adjust loss, not data—think of it as turning up the volume on minority mistakes.
⚠ Common exam trap
It's easy for candidates to choose oversampling (Option B) as the default solution for class imbalance, but fail to recognize that synthetic image generation for medical images can introduce unrealistic patterns and is not a standard or safe technique, whereas class weights are a lightweight, data-preserving approach that directly addresses the loss function.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Assign higher class weights to the positive class in the loss function
Assigning higher class weights to the positive class in the loss function directly penalizes misclassifications of the minority class during training. This forces the model to pay more attention to positive samples without altering the dataset distribution, which is critical when no additional labeled data can be obtained and the data is in a secure environment. It improves recall by increasing the gradient contribution from positive samples, while maintaining overall performance because the model still sees the original data distribution.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Undersample the majority class to balance the dataset
Why it's wrong here
Undersampling discards valuable data and may reduce model performance.
- ✗
Oversample the minority class using synthetic image generation
Why it's wrong here
Oversampling can cause overfitting, especially with limited positive samples.
- ✓
Assign higher class weights to the positive class in the loss function
Why this is correct
Class weights force the model to focus on the minority class, improving recall.
- ✗
Replace the CNN with a transformer-based architecture
Why it's wrong here
Changing architecture does not directly address class imbalance.
About these practice questions
Courseiva writes every AI0-001 question from scratch — 754 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
Same concept, more angles
2 more ways this is tested on AI0-001
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A fraud detection model is trained on a dataset where only 0.1% of transactions are fraudulent. The model achieves 99.9% accuracy but fails to catch most frauds. Which metric should the team prioritize, and which technique could help?
hard- A.Mean Squared Error; use L2 regularization
- B.F1 score; use principal component analysis
- C.Accuracy; collect more data
- ✓ D.Precision-Recall AUC; use oversampling like SMOTE
Why D: The dataset is highly imbalanced (0.1% fraud), so 99.9% accuracy is misleading because a model that predicts 'not fraud' for every transaction achieves it. Precision-Recall AUC focuses on the positive class (fraud) and is robust to class imbalance, unlike accuracy or ROC-AUC. Oversampling like SMOTE generates synthetic fraud samples to balance the dataset, helping the model learn the minority class patterns.
Variation 2. A financial institution uses a deep learning model for fraud detection. The model is a feedforward neural network with three hidden layers. It was trained on a balanced dataset of 100,000 transactions. During deployment, the model achieves high accuracy on the test set but the fraud detection rate (true positive rate) is only 40% while the false positive rate is 0.1%. The business requires a true positive rate of at least 80%. Which of the following actions is most likely to achieve the required true positive rate while minimizing the increase in false positives?
hard- A.Increase the number of hidden layers to five to capture more complex patterns
- B.Use synthetic minority oversampling (SMOTE) to rebalance the training set
- ✓ C.Change the threshold for classifying a transaction as fraud from the default 0.5 to a lower value
- D.Add L2 regularization to reduce overfitting
Why C: (increase hidden layers) may capture more complexity but does not directly increase TPR and could overfit. Option B (SMOTE) rebalances the training set, but the dataset is already balanced, so this is unlikely to improve TPR. Option D (L2 regularization) reduces overfitting but increases bias, which could lower TPR. Option C (change threshold) is the most direct approach: lowering the classification threshold increases the true positive rate, and by tuning, it can achieve 80% TPR with a minimal increase in false positives.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This AI0-001 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AI0-001 exam.