


























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



























Email has become one of the most essential communication tools in the digital era. Billions of emails are exchanged daily for personal, professional, and business purposes. However, this convenience is severely undermined by the proliferation of spam emails ā unsolicited, unwanted, or malicious messages that flood inboxes. Spam includes advertisements, phishing attempts, malware distribution, scams, and chain letters. According to various industry reports and cybersecurity analyses, spam constitutes approximately 40 ā 50% or more of global email traffic. This leads to wasted time, reduced productivity, increased storage costs, and significant security risks for individuals and organizations alike. The economic impact of spam is estimated to exceed $100 billion annually worldwide. Spam Email Classification is the process of automatically identifying whether an incoming email is legitimate (commonly called 'ham') or spam. Traditional rule-based filters ā such as keyword blacklists or sender reputation scoring ā were effective initially but failed as spam tactics evolved. Spammers increasingly use obfuscation techniques such as misspelling words (e.g., 'v1agra' instead of 'viagra'), inserting random characters, using base64-encoded content, embedding URLs in images, or using HTML rendering tricks to bypass static rules. Machine Learning (ML) and Deep Learning (DL) have revolutionized spam detection by enabling systems to learn patterns from data rather than relying on static, manually crafted rules. These models analyze a wide range of features including word frequency distributions, subject line patterns, sender metadata, email header information, attachment types, and broader contextual semantics to classify emails with consistently high accuracy.
This report explores spam email classifiers in the context of Artificial Intelligence and Machine Learning (AIML). It covers classical ML algorithms such as Naive Bayes, Support Vector Machines (SVM), and Random Forest, as well as advanced deep learning techniques involving transformer-based models such as BERT (Bidirectional Encoder Representations from Transformers). The project demonstrates practical implementation using Python, the scikit-learn
library, and Natural Language Processing (NLP) techniques applied to publicly available datasets including SpamAssassin, Enron Spam, and the UCI Spambase dataset.
sampling and random feature selection ā provides strong resistance to overfitting. Random Forest typically achieves 97ā99% accuracy on email spam datasets and handles class imbalance more gracefully than single classifiers. Gradient Boosting variants such as XGBoost and LightGBM have also demonstrated strong performance in spam classification competitions. 2.1.4 Logistic Regression and KNN Logistic Regression provides a probabilistic, interpretable baseline for binary spam classification and often achieves competitive performance with proper regularization. K-Nearest Neighbors (KNN) operates by measuring distance metrics between vectorized email representations, though its computational cost at inference time makes it less practical for large-scale deployments.
2.2.1 Bag of Words and TF-IDF The Bag of Words (BoW) model represents emails as vectors of word occurrence counts, ignoring grammar and word order. TF-IDF (Term Frequency-Inverse Document Frequency) extends BoW by weighting terms according to how frequently they appear in a document relative to their frequency across the entire corpus. High TF-IDF scores for spam-indicative words like 'free,' 'win,' 'offer,' or 'click here' help classifiers distinguish spam effectively. 2.2.2 Word Embeddings Static word embeddings such as Word2Vec (Mikolov et al., 2013) and GloVe (Pennington et al.,
Author(s) Year Method Dataset Accuracy Dada et al. 2019 Survey: NB, SVM, RF Multiple Review Almeida et al. 2020 Naive Bayes + TF-IDF SMS Spam 98.2% Rajaraman et al. 2021 Random Forest + Stemming Enron 99.2% Kaur & Singh 2022 SVM (RBF kernel) Spambase 98.7% Zhang et al. 2022 LSTM + Attention Enron + SA 99.1% Almarri 2023 Ensemble (RF+SVM+NB) Multiple 99.3% Wang et al. 2024 BERT Fine-tuned SpamAssassin 99.5% Lee & Kim 2024 Hybrid CNN-LSTM Enron 99.0% Kumar et al. 2025 RETVec + Transformer Custom 99.6% Chen et al. 2025 LLM Zero-shot Multiple 97.8%
Contemporary research focuses on several emerging challenges: multimodal spam detection that combines text content with metadata, images, and URL analysis; adversarial robustness testing that evaluates how classifiers respond to intentionally crafted spam designed to evade detection; zero-shot and few-shot learning using Large Language Models (LLMs) such as GPT-4 and Claude
Despite significant advancements in email service infrastructure ā including sophisticated filters deployed by providers such as Gmail, Microsoft Outlook, and Yahoo Mail ā spam remains a pervasive and continuously evolving threat. The core limitations of existing approaches motivate the development of a more adaptive and robust classification system.
The core problem addressed in this report can be formally stated as follows: Given a set of labeled training emails D = {(x1, y1), (x2, y2), ..., (xn, yn)}, where xi represents the feature vector extracted from email i and yi belongs to {spam, ham}, develop a classifier f: X ā Y that accurately predicts the class label for unseen emails while minimizing both false positive and false negative
error rates, maintaining computational efficiency suitable for real-time deployment, and demonstrating robustness to evolving spam tactics. This project specifically addresses binary classification (Spam vs. Ham) as a supervised learning problem and explores preprocessing strategies, feature engineering techniques, and algorithm selection choices that maximize classification accuracy on real-world email datasets.
5.1.1 Functional Requirements
5.2.1 Technical Feasibility The Python ecosystem provides a mature and well-tested set of libraries for implementing all components of this system. Key libraries include scikit-learn for traditional ML algorithms and TF-IDF vectorization, NLTK and spaCy for NLP preprocessing, pandas and NumPy for data manipulation, and matplotlib and seaborn for result visualization. GPU acceleration via TensorFlow or PyTorch is available for deep learning extensions.
5.2.2 Economic Feasibility All required software libraries are open-source and freely available. Public datasets (Enron Spam, SpamAssassin, UCI Spambase) are freely accessible. Training on standard ML algorithms requires only CPU resources, making this project highly cost-effective. Deep learning extensions would require GPU resources, available affordably through cloud platforms (Google Colab, AWS, Azure). 5.2.3 Operational Feasibility The trained model can be deployed as a REST API service using Flask or FastAPI, integrating easily with existing email infrastructure. A lightweight deployment can be embedded directly in email client plugins. The system's modular design supports incremental retraining as new labeled spam data becomes available.
The overall system architecture consists of six sequential stages, each performing a specific transformation of the input data:
Component Specification Operating System Windows 10/11 or Ubuntu 20.04+
This project utilizes the Enron Spam Dataset, which contains approximately 33,000 real-world emails labeled as spam or ham. The dataset is split using an 80%/20% stratified train-test split (80% for training, 20% for evaluation), ensuring that the class distribution is preserved in both subsets. An additional 10% of training data may be held out as a validation set for hyperparameter tuning.
Raw email text undergoes the following processing steps before feature extraction:
Text features are extracted using TF-IDF (Term Frequency-Inverse Document Frequency) vectorization. The TF-IDF score for a term t in document d is computed as: TF-IDF(t, d) = TF(t, d) x IDF(t) = (count of t in d / total terms in d) x log(N / df(t)) where N is the total number of documents and df(t) is the number of documents containing term t. Key vectorization parameters include: max_features=5000 (retaining the 5,000 most informative
terms), ngram_range=(1,2) to capture both unigram and bigram patterns, and min_df=2 to ignore extremely rare terms that may represent noise.
6.4.1 Multinomial Naive Bayes The Multinomial Naive Bayes classifier models the probability of each class given the email's word features using Bayes' theorem: P(spam|x) is proportional to P(x|spam) x P(spam). The likelihood P(x|spam) is computed as the product of individual word probabilities under the spam class. Laplace smoothing (alpha=1.0) prevents zero-probability issues for words not seen during training. 6.4.2 Support Vector Machine The SVM implementation uses a linear kernel for high-dimensional sparse TF-IDF feature vectors. The classifier finds a maximum-margin hyperplane that separates spam and ham feature vectors. The regularization parameter C controls the trade-off between maximizing the margin and minimizing classification errors on training data. 6.4.3 Random Forest The Random Forest implementation trains an ensemble of 100 decision trees, each on a bootstrapped subset of training examples and a random subset of features. The final classification is determined by majority vote across all trees. This ensemble approach reduces variance and improves generalization compared to individual decision trees. 6.4.4 Logistic Regression Logistic Regression models the probability of the spam class as a sigmoid function of a linear combination of TF-IDF features. L2 regularization (Ridge penalty) prevents overfitting. Despite its simplicity, Logistic Regression often achieves competitive performance with more complex algorithms on text classification tasks.
Hyperparameter optimization is performed using GridSearchCV with 5 - fold cross-validation. Key hyperparameters tuned for each model include: the smoothing parameter alpha for Naive Bayes, the regularization strength C for SVM and Logistic Regression, and the number of estimators and