Skip to content

Developing a Python-based spam detector using the Naive Bayes approach.

Notifications You must be signed in to change notification settings

AlmaBetter-School/Spam-Detector-sample-github

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

Email Logo.png

Spam Detector

AlmaBetter Verfied Project - AlmaBetter School

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.

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

📜 Credits

< Your Name > | Avid Learner | Data Scientist | Machine Learning Engineer | Deep Learning enthusiast

Contact me for Data Science Project Collaborations

LinkedIn Badge GitHub Badge Medium Badge Resume Badge

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

📚 References

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

About

Developing a Python-based spam detector using the Naive Bayes approach.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%