Skip to content

This project presents a Python-based spam detector program that utilizes the Naive Bayes approach to classify emails as either spam or ham. The system is designed to accurately and efficiently identify spam messages, providing a useful tool for individuals and organizations seeking to manage their email inboxes more effectively.

Notifications You must be signed in to change notification settings

ma-shamshiri/Spam-Detector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

Email Logo.png

Spam Detector

COMP 6721 - Artificial Intelligence

Project Assignment 2 - Concordia University (Winter 2020)

Animated gif pacman game

I have developed a spam detector program in Python which classifies given emails as spam or ham using the Naive Bayes approach.

💾 Project Files Description

This Project includes 3 executable files, 3 text files as well as 2 directories as follows:

Executable Files:

  • spam_detector.py - Includes all functions required for classification operations.
  • train.py - Uses the functions defined in the spam_detector.py file and generates the model.txt file after execution.
  • test.py - Uses the functions defined in the spam_detector.py file and, after execution, generates the result.txt as well as evaluation.txt files.

Output Files:

  • model.txt - Contains information about the vocabularies of the train set, such as the frequency and conditional probability of each word in Spam and Ham classes.
  • result.txt - Contains information about the classified emails of the test set.
  • evaluation.txt - Contains evaluation results table as well as Confusion Matrix of Spam and Ham classes.

Source Directories:

  • train directory - Includes all emails for the training phase of the program.
  • test directory - Includes all emails for the testing phase of the program.

-----------------------------------------------------

📖 Naive Bayes

In machine learning, naive Bayes classifiers are a family of simple "probabilistic classifiers" based on applying Bayes' theorem with strong (naive) independence assumptions between the features. Abstractly, naive Bayes is a conditional probability model: given a problem instance to be classified, represented by a vector Formula 1

representing some n features (independent variables), it assigns to this instance probabilities Formula 2

The problem with the above formulation is that if the number of features n is large or if a feature can take on a large number of values, then basing such a model on probability tables is infeasible. We therefore reformulate the model to make it more tractable. Using Bayes' theorem, the conditional probability can be decomposed as Formula 3

-----------------------------------------------------

📋 Execution Instruction

The order of execution of the program files is as follows:

1) spam_detector.py

First, the spam_detector.py file must be executed to define all the functions and variables required for classification operations.

2) train.py

Then, the train.py file must be executed, which leads to the production of the model.txt file. At the beginning of this file, the spam_detector has been imported so that the functions defined in it can be used.

3) test.py

Finally, the test.py file must be executed to create the result.txt and evaluation.txt files. Just like the train.py file, at the beginning of this file, the spam_detector has been imported so that the functions defined in it can be used.

-----------------------------------------------------

📚 References

-----------------------------------------------------

📜 Credits

Mohammad Amin Shamshiri

GitHub Badge Twitter Badge LinkedIn Badge

About

This project presents a Python-based spam detector program that utilizes the Naive Bayes approach to classify emails as either spam or ham. The system is designed to accurately and efficiently identify spam messages, providing a useful tool for individuals and organizations seeking to manage their email inboxes more effectively.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages