Code Monkey home page Code Monkey logo

email-spam-detector-machine-learning's Introduction

Spam-Detector

A Python-based spam detector using the Naive Bayes approach.

The spam detection process goes through a series of following steps:

1. Common Aspects of Text Mining:

  • Preparation of Corpus.
  • Corpus Inspection.
  • Cleansing of Corpus.
  • Tokenize the Corpus and count the word frequency.
  • Compute probabilities.

2. Naive Bayes Classifier Approach:

  • Build the Vocabulary of words by separating SPAM and HAM from training data.
  • Store vocabulary of words in a file.
  • Training the classifier on vocabulary.
  • Evaluate the performance of model on test data.
  • Generate Confusion and Evaluation Matrix.

File Structure:

.
├── Processor.py	# File Processor and Text Processor
├── Model.py		# Naive Bayes Classifier
├── main.py		# Entry point of script
├── dataset
	├── train		# Training dataset
	├── test	        # Test dataset
├── report			# Documentation for the project
├── results      		
	├── model.txt		# Saved Model
	├── result.txt  	# Classification Results
└── README.md

Processor.py

This file contains code for reading and loading the training and test documents of spam and ham class. It also consists of logic necessary to implement the steps required for classification of email such as tokenization of corpus, calculating frequency of words, computing conditional probabilities, building and storing the vocabulary and classification results.

Model.py

This python file consists of below functionalities:

  1. Methods to implement the NaiveBayes Classifier as well as calculates the parameters such as Accuracy, Precision, Recall and F1 Measure required for analysis of Model.

  2. Logic that predicts class of Email as SPAM or HAM for given document.

  3. Method for constructing the Confusion Matrix.

main.py

It instantiates the objects to call methods for corpus preparation and training classifier. It also runs classifier on test data and displays the Performance Measures for the built model.

Run Code

On the Command Prompt, run the command:

python main.py

Evaluation Matrix

  • Accuracy:
  • Recall :
  • Precision:
  • F1-Measure:

Confusion Matrix

Considering SPAM as a positive class and HAM as the negative class:

SPAM (Predicted) HAM (Predicted)
SPAM (Actual) TP = 336 FN = 64
HAM (Actual) FP = 6 TN = 394

References

email-spam-detector-machine-learning's People

Contributors

himens72 avatar jenpujara avatar khyati389 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.