Continuous Training (CT) Exam: Binary & Per-Class Classification Performance Evaluation
Question 3
Question Prompt
A machine learning model has been developed by an organization to classify incoming emails into two categories: Legitimate (Not Spam) and Spam. The model is evaluated using 500 test emails, and the following results are obtained:
| Actual \ Predicted | Not Spam | Spam |
|---|---|---|
| Not Spam | 350 | 20 |
| Spam | 30 | 100 |
The total number of observations is .
- a) Determine the classification accuracy of the email filtering system based on the given results. [5 Marks]
- b) Using the confusion matrix, compute the Precision, Recall, and F1-Score for both Not Spam and Spam classes. Show the calculations clearly. [10 Marks]
- c) Interpret the obtained evaluation metrics and assess the effectiveness of the classifier. Identify the class for which the classifier shows relatively poorer performance and justify your answer using the calculated metrics. [5 Marks]
Academic Definition of a Confusion Matrix
A Confusion Matrix is a specific cross-tabulation table (where is the number of classes) used to evaluate the performance of a supervised learning classifier on a set of test data for which the true values are known. It tabulates the frequency of actual class instances (rows) against predicted class instances (columns).
To conduct a rigorous mathematical evaluation of this system, we first compute the marginal sums (totals) of our given confusion matrix to verify structural consistency:
Marginalized Confusion Matrix Table
| Actual \ Predicted | Not Spam (Legitimate) | Spam | Actual Row Totals (Class Support) |
|---|---|---|---|
| Not Spam | (True Not Spam) | (False Spam) | |
| Spam | (False Not Spam) | (True Spam) | |
| Predicted Column Totals | Total Sample Size () |
Verification of Marginal Consistency:
- Row-wise Sum:
- Column-wise Sum: The matrix is structurally sound, and the total sample size matches .
a) Overall Classification Accuracy (5 Marks)
Formal Academic Definition: Accuracy is a global metric representing the probability that the classifier makes a correct prediction over the joint probability distribution of the classes. It is mathematically defined as the ratio of correct predictions (the sum of the diagonal elements of the confusion matrix) to the total number of evaluation instances ().
Mathematical Formula:
Step-by-Step Mathematical Derivation:
-
Identify Diagonal Correct Classifications:
- True Legitimate ():
- True Spam ():
-
Substitute into Global Accuracy Formula:
-
Perform Fractional Simplification: To express the ratio in its irreducible form, divide both the numerator and the denominator by their Greatest Common Divisor ():
-
Decimal Form:
-
Percentage Representation:
- Inference & Interpretation: The global classification accuracy of the email filtering system is 90.00%. This indicates that if an email is drawn at random from the test distribution, the probability that the model classifies it correctly is exactly . While accuracy appears robust at first glance, global accuracy is highly susceptible to majority class dominance bias in imbalanced datasets. Because legitimate emails make up 74.00% of the dataset (), a naive "majority-class classifier" that marks every email as "Not Spam" would automatically achieve a baseline accuracy of . Therefore, per-class metrics must be analyzed to evaluate the filter's practical effectiveness.
b) Precision, Recall, and F1-Score for Both Classes (10 Marks)
To compute per-class evaluation metrics, we mathematically treat each class in turn as the "Positive Target Class" (), while treating the other class as the "Negative Class" ().
1. Performance Evaluation for Class: Spam
Treating Spam as the positive class () and Not Spam as the negative class (), we map the cells of our marginalized matrix to binary classification parameters:
- True Positive (): Actual Spam predicted as Spam = 100
- True Negative (): Actual Not Spam predicted as Not Spam = 350
- False Positive (): Actual Not Spam predicted as Spam = 20 (Type I Error: Legitimate email incorrectly flagged as spam and filtered out of the inbox)
- False Negative (): Actual Spam predicted as Not Spam = 30 (Type II Error: Spam email incorrectly flagged as legitimate, slipping into the inbox)
Metric 1.1: Precision (Spam)
- Academic Definition: Precision measures the fidelity of positive predictions. It is the conditional probability that an instance is actually positive given that the model predicted it as positive: .
- Formula:
- Substitution & Step-by-Step Arithmetic: Divide the numerator and denominator by their GCD of : Perform long division ():
Metric 1.2: Recall (Spam) / Sensitivity
- Academic Definition: Recall measures the coverage of the target class. It is the conditional probability that an instance is predicted positive given that it is actually positive: .
- Formula:
- Substitution & Step-by-Step Arithmetic: Divide by their GCD of : Perform long division ():
Metric 1.3: F1-Score (Spam)
-
Academic Definition: The F1-Score is the harmonic mean of Precision and Recall. In machine learning, we use the harmonic mean instead of the arithmetic mean because the harmonic mean is highly sensitive to extreme imbalances. If either precision or recall drops to 0, the harmonic mean drops to 0, whereas the arithmetic mean would remain at 50%.
-
Method A (Direct Structural Formula): Divide numerator and denominator by their GCD of :
-
Method B (Harmonic Substitution Verification): Both independent mathematical derivations yield the exact same score, verifying calculations.
2. Performance Evaluation for Class: Not Spam (Legitimate)
Treating Not Spam as the positive class () and Spam as the negative class (), we map our binary parameters accordingly:
- True Positive (): Actual Not Spam predicted as Not Spam = 350
- True Negative (): Actual Spam predicted as Spam = 100
- False Positive (): Actual Spam predicted as Not Spam = 30 (Type I Error relative to Legitimate classification)
- False Negative (): Actual Not Spam predicted as Spam = 20 (Type II Error relative to Legitimate classification)
Metric 2.1: Precision (Not Spam)
- Academic Definition: The probability that a predicted legitimate email is actually legitimate: .
- Formula:
- Substitution & Step-by-Step Arithmetic: Divide by their GCD of : Perform long division ():
Metric 2.2: Recall (Not Spam)
- Academic Definition: The probability that an actual legitimate email is successfully identified by the system: .
- Formula:
- Substitution & Step-by-Step Arithmetic: Divide by their GCD of : Perform long division ():
Metric 2.3: F1-Score (Not Spam)
-
Method A (Direct Structural Formula): Divide numerator and denominator by their GCD of : Perform long division ():
-
Method B (Harmonic Substitution Verification): Divide numerator and denominator by their GCD of : Both independent mathematical derivations yield the exact same score, verifying calculations.
c) Interpretation, Assessment, and Justification (5 Marks)
1. Metric Interpretation Summary Table
| Class Target | Support (Actual) | Precision | Recall | F1-Score | Overall Assessment |
|---|---|---|---|---|---|
| Not Spam (Legitimate) | 370 (74.00%) | 92.11% | 94.59% | 93.33% | Excellent / Highly Robust |
| Spam | 130 (26.00%) | 83.33% | 76.92% | 80.00% | Sub-optimal / Poor Performance |
2. Class-wise Performance Assessment
The classification model exhibits relatively poorer performance on the Spam class compared to the Not Spam (Legitimate) class across all three metric areas.
3. Mathematical & Structural Justification:
- F1-Score Gap: The F1-Score of the Spam class is 80.00%, which is 13.33 percentage points lower than the F1-Score of the Not Spam class (93.33%). F1-score represents the overall quality of class predictions, showing that the model is significantly weaker at classifying spam.
- Recall as the Primary Weakness: The Recall for Spam (76.92%) is the lowest metric in the system. Out of 130 actual Spam emails, the model successfully caught only 100 (), failing to identify 30 spam messages (). This means 23.08% (almost a quarter) of spam emails slip past the filter directly into users' primary inboxes.
- Precision Deficit: The Precision for Spam is 83.33%, indicating that out of 120 emails predicted to be spam, 20 were actually Legitimate (). This corresponds to an error rate of 16.67% where important legitimate correspondence is routed to the spam folder.
4. Scientific Explanation of the Poorer Class Performance
The disparity in class performance is driven by Class Imbalance in the training/test distributions:
- Imbalance Ratio: Legitimate emails represent 74.00% of the dataset (370 out of 500), while Spam emails represent only 26.00% (130 out of 500).
- Loss Function Bias: Standard machine learning models minimize global empirical risk (total error). In an imbalanced setup, the model can maximize overall accuracy (achieving 90%) by aligning its decision boundary to fit the majority class extremely well, even if it performs poorly on the minority class.
- Consequently: The model achieves high metrics on the majority class (Not Spam: 92.11% Precision, 94.59% Recall) but performs poorly on the minority class (Spam: 83.33% Precision, 76.92% Recall).
5. Domain-Specific Operational Analysis & Recommendations
In industrial email classification, there is a fundamental trade-off between Type I and Type II errors:
- Type I Error (False Spam Flag - FP): A legitimate email is filtered as spam. The cost is extremely high because users may miss critical business emails (e.g., job offers, bank notifications, security alerts).
- Type II Error (Missed Spam - FN): A spam email slips into the inbox. The cost is low—it is simply a minor user inconvenience.
- Model Assessment: By achieving a Legitimate Recall of 94.59%, the model ensures that only 5.41% ( out of 370) of legitimate emails are lost to the spam folder. While this shows a design that prioritizes email safety, the Spam Precision of 83.33% means that 1 in 6 emails in the spam folder is actually legitimate, which is still too high for reliable business deployment.
Technical Recommendations for Full Optimization:
To optimize this classifier for real-world enterprise deployment:
- Apply Cost-Sensitive Learning: Modify the model's loss function to penalize False Positives (legitimate emails marked as spam) much more heavily than False Negatives.
- Adjust the Decision Threshold (Threshold Moving): Currently, the decision threshold is likely set at the standard . By plotting a Receiver Operating Characteristic (ROC) or Precision-Recall Curve, the threshold can be adjusted (e.g., ) to raise the precision of spam flagging, protecting legitimate emails even if it slightly decreases spam recall.
- Use SMOTE (Synthetic Minority Over-sampling Technique): Over-sample the minority class (Spam) synthetically during model training to eliminate the majority class bias, prompting the model to learn more distinct boundaries for spam patterns.