All projects

Project P-01 · Dublin City University coursework

Phishing email classification

This project tackles the critical challenge of email phishing detection. It uses various machine learning models, including the pre-trained BERT (Bidirectional Encoder Representations from Transformers) model, to distinguish between phishing (spam) and legitimate (non-spam) emails.

Code
Repository on GitHub
Credit
With Bohdan Boiprav
Stack
Python · PyTorch · Hugging Face Transformers · LIME
Illustrative photo: a phone showing a phishing email warning.

01 What it is

The script is a toolkit for evaluating and comparing the performance of different machine learning models on the task of email classification. These models include:

  • Logistic Regression
  • Decision Trees
  • Random Forests
  • Gradient Boosting
  • Naive Bayes
  • Multi-Layer Perceptrons

By analysing the performance of these models, you can identify the most effective approach for accurately classifying emails and protecting users from phishing scams.

02 Method

  • Data preparation. Loads and preprocesses email data from a CSV file, including label encoding and splitting the dataset for training and evaluation.
  • Custom email dataset class. A custom EmailDataset class handles tokenisation so the data meets the BERT model’s input requirements.
  • Model comparison. Trains and evaluates Logistic Regression, Decision Trees, Random Forests, Gradient Boosting, Naive Bayes and Multi-Layer Perceptrons on the same task.
  • BERT in action. Uses PyTorch and the Hugging Face Transformers library to train and optimise a BERT model specifically for email classification.
  • Making predictions. A predict function classifies new emails as phishing or safe with the trained models.
  • Saving trained models. Model states are saved, so they can be reloaded for classification without retraining.
  • Understanding predictions. The LIME (Local Interpretable Model-Agnostic Explanations) library explains the model’s predictions on specific emails.

03 Tools

  • Python
  • PyTorch
  • Hugging Face Transformers
  • BERT
  • LIME
  • Logistic Regression
  • Decision Trees
  • Random Forests
  • Gradient Boosting
  • Naive Bayes
  • Multi-Layer Perceptrons

04 Evaluation

To assess each model during training, the script calculates training and validation loss, accuracy, precision, recall and F1-score.

05 Credits

Authors: Bohdan Boiprav & Catalin Bondari. Dublin City University coursework. Licensed under the MIT License.

Next project

Telegram BI bot