Skip to main content

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 \ PredictedNot SpamSpam
Not Spam35020
Spam30100

The total number of observations is N=500N = 500.

  • 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 C×CC \times C cross-tabulation table (where CC 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:

N=row=1Ccol=1CMrow,colN = \sum_{row=1}^{C} \sum_{col=1}^{C} M_{row, col}

Marginalized Confusion Matrix Table

Actual \ PredictedNot Spam (Legitimate)SpamActual Row Totals (Class Support)
Not SpamM1,1=350M_{1,1} = 350 (True Not Spam)M1,2=20M_{1,2} = 20 (False Spam)350+20=370350 + 20 = \mathbf{370}
SpamM2,1=30M_{2,1} = 30 (False Not Spam)M2,2=100M_{2,2} = 100 (True Spam)30+100=13030 + 100 = \mathbf{130}
Predicted Column Totals350+30=380350 + 30 = \mathbf{380}20+100=12020 + 100 = \mathbf{120}Total Sample Size (NN) =500= \mathbf{500}

Verification of Marginal Consistency:

  • Row-wise Sum: Total Legitimate+Total Spam=370+130=500\text{Total Legitimate} + \text{Total Spam} = 370 + 130 = \mathbf{500}
  • Column-wise Sum: Predicted Legitimate+Predicted Spam=380+120=500\text{Predicted Legitimate} + \text{Predicted Spam} = 380 + 120 = \mathbf{500} The matrix is structurally sound, and the total sample size matches N=500N = 500.

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 (NN).

Mathematical Formula:

Accuracy=i=1CMi,iN=TP+TNTP+TN+FP+FNAccuracy = \frac{\sum_{i=1}^{C} M_{i,i}}{N} = \frac{TP + TN}{TP + TN + FP + FN}

Step-by-Step Mathematical Derivation:

  1. Identify Diagonal Correct Classifications:

    • True Legitimate (M1,1M_{1,1}): 350350
    • True Spam (M2,2M_{2,2}): 100100 Sum of Correct Predictions=350+100=450\text{Sum of Correct Predictions} = 350 + 100 = 450
  2. Substitute into Global Accuracy Formula: Accuracy=450500Accuracy = \frac{450}{500}

  3. Perform Fractional Simplification: To express the ratio in its irreducible form, divide both the numerator and the denominator by their Greatest Common Divisor (GCD=50\text{GCD} = 50): Accuracy=450÷50500÷50=910Accuracy = \frac{450 \div 50}{500 \div 50} = \frac{9}{10}

  4. Decimal Form: Accuracy=0.9000Accuracy = 0.9000

  5. Percentage Representation: Accuracy=0.9000×100%=90.00%Accuracy = 0.9000 \times 100\% = \mathbf{90.00\%}

  • 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 0.900.90. While 90%90\% 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 (370500\frac{370}{500}), a naive "majority-class classifier" that marks every email as "Not Spam" would automatically achieve a baseline accuracy of 74.00%74.00\%. 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" (11), while treating the other class as the "Negative Class" (00).


1. Performance Evaluation for Class: Spam

Treating Spam as the positive class (11) and Not Spam as the negative class (00), we map the cells of our marginalized matrix to binary classification parameters:

  • True Positive (TPSpamTP_{\text{Spam}}): Actual Spam predicted as Spam = 100
  • True Negative (TNSpamTN_{\text{Spam}}): Actual Not Spam predicted as Not Spam = 350
  • False Positive (FPSpamFP_{\text{Spam}}): Actual Not Spam predicted as Spam = 20 (Type I Error: Legitimate email incorrectly flagged as spam and filtered out of the inbox)
  • False Negative (FNSpamFN_{\text{Spam}}): 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: P(Actual=SpamPredicted=Spam)P(\text{Actual} = \text{Spam} \mid \text{Predicted} = \text{Spam}).
  • Formula: PrecisionSpam=TPSpamTPSpam+FPSpamPrecision_{\text{Spam}} = \frac{TP_{\text{Spam}}}{TP_{\text{Spam}} + FP_{\text{Spam}}}
  • Substitution & Step-by-Step Arithmetic: PrecisionSpam=100100+20Precision_{\text{Spam}} = \frac{100}{100 + 20} PrecisionSpam=100120Precision_{\text{Spam}} = \frac{100}{120} Divide the numerator and denominator by their GCD of 2020: PrecisionSpam=100÷20120÷20=56Precision_{\text{Spam}} = \frac{100 \div 20}{120 \div 20} = \frac{5}{6} Perform long division (5÷65 \div 6): PrecisionSpam=0.83333333...83.33%Precision_{\text{Spam}} = 0.83333333... \rightarrow \mathbf{83.33\%}
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: P(Predicted=SpamActual=Spam)P(\text{Predicted} = \text{Spam} \mid \text{Actual} = \text{Spam}).
  • Formula: RecallSpam=TPSpamTPSpam+FNSpamRecall_{\text{Spam}} = \frac{TP_{\text{Spam}}}{TP_{\text{Spam}} + FN_{\text{Spam}}}
  • Substitution & Step-by-Step Arithmetic: RecallSpam=100100+30Recall_{\text{Spam}} = \frac{100}{100 + 30} RecallSpam=100130Recall_{\text{Spam}} = \frac{100}{130} Divide by their GCD of 1010: RecallSpam=100÷10130÷10=1013Recall_{\text{Spam}} = \frac{100 \div 10}{130 \div 10} = \frac{10}{13} Perform long division (10÷1310 \div 13): RecallSpam=0.76923076...76.92%Recall_{\text{Spam}} = 0.76923076... \rightarrow \mathbf{76.92\%}
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): F1Spam=2TPSpam2TPSpam+FPSpam+FNSpamF1_{\text{Spam}} = \frac{2 \cdot TP_{\text{Spam}}}{2 \cdot TP_{\text{Spam}} + FP_{\text{Spam}} + FN_{\text{Spam}}} F1Spam=21002100+20+30F1_{\text{Spam}} = \frac{2 \cdot 100}{2 \cdot 100 + 20 + 30} F1Spam=200200+50=200250F1_{\text{Spam}} = \frac{200}{200 + 50} = \frac{200}{250} Divide numerator and denominator by their GCD of 5050: F1Spam=200÷50250÷50=45=0.800080.00%F1_{\text{Spam}} = \frac{200 \div 50}{250 \div 50} = \frac{4}{5} = 0.8000 \rightarrow \mathbf{80.00\%}

  • Method B (Harmonic Substitution Verification): F1Spam=2PrecisionSpamRecallSpamPrecisionSpam+RecallSpam=2(56)(1013)(56)+(1013)F1_{\text{Spam}} = 2 \cdot \frac{Precision_{\text{Spam}} \cdot Recall_{\text{Spam}}}{Precision_{\text{Spam}} + Recall_{\text{Spam}}} = 2 \cdot \frac{\left(\frac{5}{6}\right) \cdot \left(\frac{10}{13}\right)}{\left(\frac{5}{6}\right) + \left(\frac{10}{13}\right)} F1Spam=25078513+10678=2507865+6078=250125=225=45=80.00%F1_{\text{Spam}} = 2 \cdot \frac{\frac{50}{78}}{\frac{5 \cdot 13 + 10 \cdot 6}{78}} = 2 \cdot \frac{\frac{50}{78}}{\frac{65 + 60}{78}} = 2 \cdot \frac{50}{125} = 2 \cdot \frac{2}{5} = \frac{4}{5} = \mathbf{80.00\%} 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 (11) and Spam as the negative class (00), we map our binary parameters accordingly:

  • True Positive (TPNot SpamTP_{\text{Not Spam}}): Actual Not Spam predicted as Not Spam = 350
  • True Negative (TNNot SpamTN_{\text{Not Spam}}): Actual Spam predicted as Spam = 100
  • False Positive (FPNot SpamFP_{\text{Not Spam}}): Actual Spam predicted as Not Spam = 30 (Type I Error relative to Legitimate classification)
  • False Negative (FNNot SpamFN_{\text{Not Spam}}): 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: P(Actual=Not SpamPredicted=Not Spam)P(\text{Actual} = \text{Not Spam} \mid \text{Predicted} = \text{Not Spam}).
  • Formula: PrecisionNot Spam=TPNot SpamTPNot Spam+FPNot SpamPrecision_{\text{Not Spam}} = \frac{TP_{\text{Not Spam}}}{TP_{\text{Not Spam}} + FP_{\text{Not Spam}}}
  • Substitution & Step-by-Step Arithmetic: PrecisionNot Spam=350350+30Precision_{\text{Not Spam}} = \frac{350}{350 + 30} PrecisionNot Spam=350380Precision_{\text{Not Spam}} = \frac{350}{380} Divide by their GCD of 1010: PrecisionNot Spam=350÷10380÷10=3538Precision_{\text{Not Spam}} = \frac{350 \div 10}{380 \div 10} = \frac{35}{38} Perform long division (35÷3835 \div 38): PrecisionNot Spam=0.92105263...92.11%Precision_{\text{Not Spam}} = 0.92105263... \rightarrow \mathbf{92.11\%}
Metric 2.2: Recall (Not Spam)
  • Academic Definition: The probability that an actual legitimate email is successfully identified by the system: P(Predicted=Not SpamActual=Not Spam)P(\text{Predicted} = \text{Not Spam} \mid \text{Actual} = \text{Not Spam}).
  • Formula: RecallNot Spam=TPNot SpamTPNot Spam+FNNot SpamRecall_{\text{Not Spam}} = \frac{TP_{\text{Not Spam}}}{TP_{\text{Not Spam}} + FN_{\text{Not Spam}}}
  • Substitution & Step-by-Step Arithmetic: RecallNot Spam=350350+20Recall_{\text{Not Spam}} = \frac{350}{350 + 20} RecallNot Spam=350370Recall_{\text{Not Spam}} = \frac{350}{370} Divide by their GCD of 1010: RecallNot Spam=350÷10370÷10=3537Recall_{\text{Not Spam}} = \frac{350 \div 10}{370 \div 10} = \frac{35}{37} Perform long division (35÷3735 \div 37): RecallNot Spam=0.94594594...94.59%Recall_{\text{Not Spam}} = 0.94594594... \rightarrow \mathbf{94.59\%}
Metric 2.3: F1-Score (Not Spam)
  • Method A (Direct Structural Formula): F1Not Spam=2TPNot Spam2TPNot Spam+FPNot Spam+FNNot SpamF1_{\text{Not Spam}} = \frac{2 \cdot TP_{\text{Not Spam}}}{2 \cdot TP_{\text{Not Spam}} + FP_{\text{Not Spam}} + FN_{\text{Not Spam}}} F1Not Spam=23502350+30+20=700700+50=700750F1_{\text{Not Spam}} = \frac{2 \cdot 350}{2 \cdot 350 + 30 + 20} = \frac{700}{700 + 50} = \frac{700}{750} Divide numerator and denominator by their GCD of 5050: F1Not Spam=700÷50750÷50=1415F1_{\text{Not Spam}} = \frac{700 \div 50}{750 \div 50} = \frac{14}{15} Perform long division (14÷1514 \div 15): F1Not Spam=0.93333333...93.33%F1_{\text{Not Spam}} = 0.93333333... \rightarrow \mathbf{93.33\%}

  • Method B (Harmonic Substitution Verification): F1Not Spam=2PrecisionNot SpamRecallNot SpamPrecisionNot Spam+RecallNot Spam=2(3538)(3537)(3538)+(3537)F1_{\text{Not Spam}} = 2 \cdot \frac{Precision_{\text{Not Spam}} \cdot Recall_{\text{Not Spam}}}{Precision_{\text{Not Spam}} + Recall_{\text{Not Spam}}} = 2 \cdot \frac{\left(\frac{35}{38}\right) \cdot \left(\frac{35}{37}\right)}{\left(\frac{35}{38}\right) + \left(\frac{35}{37}\right)} F1Not Spam=2122514063537+35381406=2122514061295+13301406=212252625F1_{\text{Not Spam}} = 2 \cdot \frac{\frac{1225}{1406}}{\frac{35 \cdot 37 + 35 \cdot 38}{1406}} = 2 \cdot \frac{\frac{1225}{1406}}{\frac{1295 + 1330}{1406}} = 2 \cdot \frac{1225}{2625} Divide numerator and denominator by their GCD of 175175: F1Not Spam=21225÷1752625÷175=2715=141593.33%F1_{\text{Not Spam}} = 2 \cdot \frac{1225 \div 175}{2625 \div 175} = 2 \cdot \frac{7}{15} = \frac{14}{15} \approx \mathbf{93.33\%} Both independent mathematical derivations yield the exact same score, verifying calculations.


c) Interpretation, Assessment, and Justification (5 Marks)

1. Metric Interpretation Summary Table

Class TargetSupport (Actual)PrecisionRecallF1-ScoreOverall Assessment
Not Spam (Legitimate)370 (74.00%)92.11%94.59%93.33%Excellent / Highly Robust
Spam130 (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 (TP=100TP = 100), failing to identify 30 spam messages (FN=30FN = 30). 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 (FP=20FP = 20). 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:

  1. 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).
  2. 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.
  3. 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% (2020 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:

  1. 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.
  2. Adjust the Decision Threshold (Threshold Moving): Currently, the decision threshold is likely set at the standard τ=0.5\tau = 0.5. By plotting a Receiver Operating Characteristic (ROC) or Precision-Recall Curve, the threshold can be adjusted (e.g., τ=0.7\tau = 0.7) to raise the precision of spam flagging, protecting legitimate emails even if it slightly decreases spam recall.
  3. 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.