Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

spam-ham

SMS SPAM DETECTION

This project implements a spam detection model that classifies SMS messages as spam or ham (not spam) using Natural Language Processing (NLP) and Machine Learning.

PROJECT OVERVIEW---------------------------------------------------------------

Goal: Automatically detect spam messages from SMS text.

Dataset: SMSSpamCollection dataset with 5,572 messages labeled as spam or ham.

Approach:

Preprocessing and cleaning text

Feature extraction using Bag-of-Words (BoW)

Train-test split

Model training with Multinomial Naive Bayes

Evaluation using accuracy, precision, recall, and F1-score

DATASET-----------------------------------------------------------------------

The dataset SMSSpamCollection.txt contains:

Column Description label spam or ham message SMS text content

The dataset is tab-separated (\t) and has no header row.

DATA PREPROCESSING------------------------------------------------------------

Remove non-alphabetic characters

Convert text to lowercase

Tokenize words

Remove stopwords

Apply Porter Stemming

Reconstruct cleaned messages into a corpus for feature extraction

FEATURE EXTRACTION----------------------------------------------------------------

Bag-of-Words (BoW):

Max features: 2,500

N-grams: 1-2

Transform text corpus into numeric vectors suitable for model input

MODEL TRAINING----------------------------------------------------------------------

Algorithm: Multinomial Naive Bayes (suitable for text classification)

Training/Test Split: 80% training, 20% testing

from sklearn.naive_bayes import MultinomialNB spamdetectmodel = MultinomialNB().fit(x_train, y_train) y_pred = spamdetectmodel.predict(x_test)

EVALUATION--------------------------------------------------------------------------

The model is evaluated using:

Accuracy

Precision

Recall

F1-score

Example Performance precision recall f1-score support

       0       0.95      0.93      0.94       149
       1       0.99      0.99      0.99       966

accuracy                           0.98      1115

macro avg 0.97 0.96 0.96 1115 weighted avg 0.98 0.98 0.98 1115

Accuracy: 98%

The model performs very well at detecting spam, with slightly lower recall for ham messages.

TOOLS AND LIBRARIES---------------------------------------------------------------------

Python 3.10

Pandas, NumPy

Scikit-learn

NLTK (Stopwords, PorterStemmer)

Regex (re)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages