Skip to content
About the project · CSNB5213 Machine Learning and Data Analytics

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.

Problem statement

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.

Dataset

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 →
01Objectives

Three objectives,
each with evidence.

  1. 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.

  2. 02

    Select a classifier using only training data.

    Both models compared on mean spam F1 across the same five validation folds; winning settings reported.

  3. 03

    Measure usefulness on unseen SMS.

    Test precision, recall, F1 and false alerts compared against an always-ham baseline; mistakes inspected.

02Methodology

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.

Data01

SMS Spam Collection CSV. v1 = label (ham/spam), v2 = text. The three mostly empty unnamed columns are not used.

Cleaning02

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.

Split03

80 / 20 stratified by label, random_state = 42: 4,100 training and 1,026 test messages.

Features04

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.

Models05

Logistic Regression (C ∈ {1, 3, 10}) and Multinomial Naive Bayes (α ∈ {0.1, 0.5, 1}) inside identical scikit-learn pipelines.

Selection06

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.

03Model selection & findings

Naive Bayes,
on the evidence.

Validation
92.02% vs 91.13%

Mean 5-fold spam F1, NB vs LR. NB chosen on this basis alone.

Test
91.21% vs 86.81%

Spam F1 on 1,026 unseen messages: 7 more spam caught, 3 fewer false alerts.

Baseline
87.72% accuracy

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.

04Limitations

Where these results
do and don't apply.

Historical corpus

The messages are from an older collection; today's spam campaigns use different wording, links and formats.

Single random split

Test results come from one random 80/20 split of the same corpus. Similar campaign templates may still appear in both partitions.

Not validated on Malaysian SMS

Malay and mixed Malay–English messages have not been independently evaluated. Results should not be assumed to transfer.

Words without order

Word-level TF-IDF ignores word order and most context, so “free” as availability and “free” as a prize look alike.

Errors in both directions

False positives (4 legitimate messages flagged) and false negatives (17 spam missed) both occurred on the test set.

Lost characters

Cleaning discards currency symbols, emoji and non-ASCII letters, and some source messages have fragments outside the v2 column.

05Future improvements

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.

→ 01

Character n-grams

Recognise variants such as “fr33”, “FREEmsg” and spacing tricks that defeat whole-word features.

→ 02

Word bigrams

Capture short phrases (“call now”, “get free”) to recover some of the context single words lose.

→ 03

Recent Malaysian SMS

Freeze the pipeline and test it on a fresh, labelled collection; report recall and false alerts by language.

→ 04

Multilingual classification

Extend preprocessing and features to Malay, English and code-mixed messages.

06Group 1 · Section 02B

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
References
  1. Almeida, T., & Hidalgo, J. (2011). SMS Spam Collection [Dataset]. UCI Machine Learning Repository. doi.org/10.24432/C5CC84
  2. Scikit-learn developers. Text feature extraction and TF-IDF term weighting. scikit-learn.org
  3. Scikit-learn developers. Multinomial Naive Bayes. scikit-learn.org
  4. Scikit-learn developers. Logistic regression. scikit-learn.org
  5. Scikit-learn developers. Tuning the hyper-parameters of an estimator. scikit-learn.org