Courseiva

Class Imbalance in Spam Classification

A data scientist trains a classification model to predict whether an email is spam or not. The model achieves 98% accuracy on the test set, but upon inspection, it classifies all emails as 'not spam' because the dataset has 95% non-spam emails. What is the most likely issue?

Quick Answer

The answer is data imbalance, as the model’s 98% accuracy is misleading because it simply predicts all emails as “not spam,” reflecting the 95% majority class in the dataset. This is a classic symptom of class imbalance in classification models, where the algorithm exploits the skewed distribution rather than learning meaningful patterns to distinguish spam from non-spam. On the Microsoft Azure AI Fundamentals AI-900 exam, this scenario tests your understanding of how accuracy can be a poor metric when classes are imbalanced, often appearing in questions about evaluating model performance. A common trap is to assume high accuracy always means a good model, but the real issue is that the minority class (spam) is ignored entirely. To remember this, think of the “95% trap”: if your accuracy is close to the majority class percentage, suspect imbalance.

⚠ Common exam trap

The trap here is that candidates see 98% accuracy and assume the model is performing well, failing to recognize that accuracy is meaningless when the dataset is highly imbalanced and the model simply predicts the majority class.

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

Data imbalance

The model achieves 98% accuracy by simply predicting all emails as 'not spam', which reflects the 95% majority class in the dataset. This is a classic symptom of class imbalance, where the model learns to exploit the skewed distribution rather than learning meaningful patterns to distinguish spam from non-spam. In Azure Machine Learning, techniques like SMOTE or stratified sampling are used to mitigate this issue.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Overfitting

    Why it's wrong here

    Overfitting occurs when a model learns training data too well and fails to generalize, typically resulting in a large gap between training and test accuracy. Here the accuracy is suspiciously high on the test set, but the model is trivial, not overfitted.

  • Underfitting

    Why it's wrong here

    Underfitting happens when a model is too simple to capture patterns, leading to low accuracy on both training and test sets. That does not match the 98% accuracy.

  • Data imbalance

    Why this is correct

    Data imbalance, where one class vastly outnumbers the other, can cause a model to predict the majority class exclusively. Accuracy is misleading in such cases; the model has not learned to identify spam.

  • Feature scaling error

    Why it's wrong here

    Feature scaling issues can affect model convergence or performance, but they do not cause a model to output a constant class prediction unless combined with other factors.

About these practice questions

Courseiva writes every AI-900 question from scratch — 985 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 →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

3 more ways this is tested on AI-900

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 data scientist trains a classification model to predict whether an email is 'phishing' or 'legitimate'. The model achieves 99% accuracy on the training data but only 68% accuracy on the test data. Which action is most likely to help improve the model's generalization performance?

medium
  • A.Increase the number of training epochs significantly.
  • B.Apply regularization techniques such as L1 or L2 regularization.
  • C.Remove some of the training data to make the dataset smaller.
  • D.Add more layers and neurons to the neural network.

Why B: The model's high training accuracy (99%) paired with much lower test accuracy (68%) is a classic sign of overfitting, where the model has memorized the training data rather than learning generalizable patterns. Regularization techniques like L1 (Lasso) or L2 (Ridge) add a penalty to the loss function that discourages overly complex models by shrinking the weights of less important features, directly reducing overfitting and improving generalization on unseen data.

Variation 2. What is 'imbalanced classification' handling using 'SMOTE'?

medium
  • A.A technique for collecting more real minority class examples from external data sources
  • B.Generating synthetic minority class examples by interpolating between existing examples
  • C.Removing majority class examples until all classes have equal representation
  • D.Setting model confidence thresholds to classify more examples as the minority class

Why B: SMOTE (Synthetic Minority Over-sampling Technique) is a data augmentation method that creates synthetic examples for the minority class by interpolating between existing minority class instances. It selects a minority example, finds its k-nearest neighbors from the same class, and generates new samples along the line segments connecting the example to those neighbors. This balances the class distribution without duplicating existing data or discarding majority class examples.

Variation 3. A data scientist is training a model to classify customer reviews as positive, negative, or neutral. The dataset contains 10,000 reviews, but only 500 of them are negative. The data scientist wants to ensure the model performs well on the minority class (negative reviews). Which technique should the data scientist consider to address the class imbalance?

medium
  • A.Increase the learning rate
  • B.Add more features to the model
  • C.Use a resampling technique like SMOTE or random oversampling of the minority class
  • D.Use L1 regularization (Lasso)

Why C: Resampling techniques like SMOTE (Synthetic Minority Oversampling Technique) or random oversampling directly address class imbalance by generating synthetic samples or duplicating existing samples from the minority class (negative reviews). This balances the training dataset, preventing the model from being biased toward the majority class (positive/neutral reviews) and improving recall for the minority class.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This AI-900 practice question is part of Courseiva's free Microsoft 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 AI-900 exam.