Can the words alone
give spam away?
An SMS filter must catch spam without hiding legitimate messages. Because most messages are legitimate, a filter can look highly accurate while catching nothing. The project asks which of two text classifiers best balances catching spam and avoiding false alerts.
This is supervised binary classification. During training, the algorithm sees SMS texts paired with known labels. When a new SMS arrives, it receives only the text and predicts one of two labels: ham or spam.
The SMS Spam Collection (Almeida & Hidalgo, 2011, UCI Machine Learning Repository) combines legitimate messages from the NUS SMS Corpus with spam reported to the UK Grumbletext forum. The group used the supplied CSV of 5,572 rows (13.41% spam) rather than collecting or relabelling messages.
Explore the dataset →Three objectives,
each with evidence.
- 01
Prepare a dataset of uniquely worded, labelled messages.
Rows and classes counted before and after cleaning (5,572 → 5,126); zero identical cleaned messages across the split.
- 02
Select a classifier using only training data.
Both models compared on mean spam F1 across the same five validation folds; winning settings reported.
- 03
Measure usefulness on unseen SMS.
Test precision, recall, F1 and false alerts compared against an always-ham baseline; mistakes inspected.
A fair contest,
decided on training data.
Both learners received exactly the same cleaned messages, folds and TF-IDF settings. The test set stayed sealed until the choice was made.
SMS Spam Collection CSV. v1 = label (ham/spam), v2 = text. The three mostly empty unnamed columns are not used.
Drop missing and exact duplicate rows → lowercase → replace punctuation & non-ASCII with spaces → keep ASCII letters and digits → collapse whitespace → drop empty and label-conflicting texts → keep one copy of each cleaned SMS.
80 / 20 stratified by label, random_state = 42: 4,100 training and 1,026 test messages.
TF-IDF, up to 3,000 terms chosen by training frequency, English stop words removed, smoothed IDF, L2 normalisation. Fitted inside each training fold only.
Logistic Regression (C ∈ {1, 3, 10}) and Multinomial Naive Bayes (α ∈ {0.1, 0.5, 1}) inside identical scikit-learn pipelines.
GridSearchCV with five stratified folds, scoring = spam F1. Best: LR C = 10 (91.13%), NB α = 0.1 (92.02%). NB selected before the test set was used.
Naive Bayes,
on the evidence.
Mean 5-fold spam F1, NB vs LR. NB chosen on this basis alone.
Spam F1 on 1,026 unseen messages: 7 more spam caught, 3 fewer false alerts.
Always predicting ham. Catches 0 of 126 spam, showing why accuracy alone misleads.
On the test set the selected classifier caught 109 of 126 spam messages with 4 false alerts. It outperformed both alternatives on spam F1, but the 17 missed messages show why a ham prediction cannot guarantee that a message is safe.
Where these results
do and don't apply.
The messages are from an older collection; today's spam campaigns use different wording, links and formats.
Test results come from one random 80/20 split of the same corpus. Similar campaign templates may still appear in both partitions.
Malay and mixed Malay–English messages have not been independently evaluated. Results should not be assumed to transfer.
Word-level TF-IDF ignores word order and most context, so “free” as availability and “free” as a prize look alike.
False positives (4 legitimate messages flagged) and false negatives (17 spam missed) both occurred on the test set.
Cleaning discards currency symbols, emoji and non-ASCII letters, and some source messages have fragments outside the v2 column.
What we would
test next.
Each change would be compared against the current word features using the same training-fold protocol, with fresh data for the final assessment.
Character n-grams
Recognise variants such as “fr33”, “FREEmsg” and spacing tricks that defeat whole-word features.
Word bigrams
Capture short phrases (“call now”, “get free”) to recover some of the context single words lose.
Recent Malaysian SMS
Freeze the pipeline and test it on a fresh, labelled collection; report recall and false alerts by language.
Multilingual classification
Extend preprocessing and features to Malay, English and code-mixed messages.
The team.
CSNB5213 Machine Learning and Data Analytics, Semester 1 2026/2027. Presented 4 December 2026.
- Irfan Hakimi bin Ahmad LutfiCS01085090
- Feng YuxinCS01087232
- Yu LuCS01087241
- Abdulla Umar Haziq bin AzisCS01085097
- Ahmad Danial bin EzamCS01085153
- Almeida, T., & Hidalgo, J. (2011). SMS Spam Collection [Dataset]. UCI Machine Learning Repository. doi.org/10.24432/C5CC84
- Scikit-learn developers. Text feature extraction and TF-IDF term weighting. scikit-learn.org
- Scikit-learn developers. Multinomial Naive Bayes. scikit-learn.org
- Scikit-learn developers. Logistic regression. scikit-learn.org
- Scikit-learn developers. Tuning the hyper-parameters of an estimator. scikit-learn.org