Machine Learning · NLP · Data Quality
Email Classification
& Intelligent Triage
Can a model catch spam while avoiding false alerts that could hide legitimate email? I built and evaluated a text-classification workflow designed around that tradeoff.
01 · Final Result
Held-out evaluation
I selected character-based TF-IDF with balanced Logistic Regression using development data, then evaluated the fixed configuration on 1,251 held-out emails.
The held-out result reached 94.36%, missing the target by 0.64 percentage points. I did not change the selected model or its 0.50 threshold after seeing this result.
02 · Data & Evaluation Design
Protecting the evaluation from matching copies
The labeled dataset contains 8,348 emails. Because matching subject-and-body content appears in multiple rows, I grouped matching content before splitting the data. This prevents defined exact matches from appearing across training, validation, and held-out test sets.
03 · Project Workflow
From raw email data to final evaluation
I developed the project in six stages so that data quality, model selection, and final evaluation remained separate.
04 · Model Development
Turning email text into model features
Models cannot work directly with raw email text. I used TF-IDF to convert text patterns into numerical features, then compared Logistic Regression configurations using development data.
TF-IDF
TF-IDF gives a text pattern more weight when it is useful in a particular email but less common across the overall training data.
The selected model used character patterns of 3–5 characters, allowing it to learn pieces of words and modified text rather than relying only on complete words.
Logistic Regression
Logistic Regression combines the TF-IDF features using learned weights and produces an estimated probability that an email is spam.
The selected model used a 0.50 classification threshold.
P(spam) = 1 / (1 + e−z)
Comparing candidate configurations
I compared multiple TF-IDF and Logistic Regression configurations using validation data before selecting the final model.
05 · Final Evaluation
What happened on unseen email
After selecting the model using development data, I kept the configuration fixed and evaluated it once on 1,251 held-out emails. The confusion matrix shows exactly where the model was correct and where it made mistakes.
Reading the result
The model caught 318 of 321 spam emails, leaving only 3 spam emails undetected. The more important tradeoff for this project was protecting legitimate email: 19 legitimate emails were incorrectly flagged as spam. That produced 94.36% spam precision, slightly below the 95% development target.
06 · Follow-Up Investigation
Could another classifier improve the tradeoff?
After the original held-out evaluation was complete, I tested Linear SVC using the saved development data while keeping the same character TF-IDF features. The goal was to identify a promising candidate for future evaluation — not to replace the original held-out result.
Logistic Regression
Validation spam precision 96.32% Validation spam recall 97.82%Linear SVC
Validation spam precision 97.55% Validation spam recall 99.38%Development error comparison
Was the improvement consistent?
I also compared spam precision across five grouped training folds. Logistic Regression averaged 95.53%, while Linear SVC averaged 97.69%. The lowest Linear SVC fold was 95.42%.
Linear SVC was explored after the original held-out results were already known. Therefore, these development results are not a new blind final test and do not replace the Logistic Regression held-out result. The next step would be to freeze the Linear SVC configuration and evaluate it on fresh, independently labeled email.
07 · Conclusion
What this project demonstrated
This project went beyond training a classifier. The main challenge was designing a trustworthy evaluation process, choosing a model around a practical error tradeoff, and keeping later experimentation separate from the original held-out result.
Final takeaway: The selected Logistic Regression model caught 318 of 321 spam emails, but its 94.36% spam precision remained slightly below the 95% development target. The later Linear SVC results provide a promising direction for future testing, not a replacement for the original final result.