P4_Approach_Spam and Ham Classification

Author

Ummay Rukiya

Published

December 1, 2026

Overview

For this project, I plan to build a model in R that classifies emails as spam or ham. Spam refers to unwanted emails, while ham refers to legitimate emails. I want to see how well a model can classify emails it has not already seen.

Data Source

I will use the Apache SpamAssassin public corpus. I plan to start with the 20030228_easy_ham and 20030228_spam archives. These contain separate collections of legitimate and spam emails, which will provide the labels for the analysis.

Planned Approach

First, I will download and extract the files using R. I will read each email into a dataframe with its text, document ID, and class label. Before building the model, I will check for empty messages, duplicate emails, and problems reading the text.

Next, I will divide the data into training and testing sets, using about 80% for training and 20% for testing. I will preserve approximately the same class proportions in both sets and set a random seed so the split can be reproduced. Duplicate messages will be removed before splitting so the same email does not appear in both sets.

I will prepare the email text by separating it into words and creating numerical features based on word counts. I will exclude routing headers and other metadata that could reveal the source or label. The vocabulary and any preprocessing decisions that depend on the data will be learned from the training set and then applied to the testing set.

I plan to start with a Naive Bayes classifier. It will use the words in the labeled training emails to learn patterns associated with spam and ham. Then I will use it to predict the labels of the withheld test emails.

Evaluating the Results

I will compare the predicted labels with the actual labels using a confusion matrix. I will also calculate accuracy, precision, recall, and F1 score, treating spam as the positive class. I will compare accuracy with a baseline that always predicts the most common training class.

I am especially interested in legitimate emails incorrectly classified as spam because those mistakes could cause someone to miss an important message. I will examine examples of both types of errors to understand where the model struggles.

Anticipated Challenges

The emails may contain HTML, unusual characters, attachments, or inconsistent formatting. I will document how these are handled and focus on readable message text. There may also be more ham messages than spam messages, so accuracy alone may not give a complete picture of performance.

Another limitation is that this is an older dataset. Results on these emails may not reflect how well the model would identify spam today.

Expected Outcome

The final report will show how the emails were collected, prepared, and classified. It will include predictions for the test set, evaluation results, and examples of classification mistakes. All code and explanations will be included in a Quarto document.

References

Apache SpamAssassin. Public corpus. https://spamassassin.apache.org/old/publiccorpus/