DS Using Python Lab Mini-Project Report
AI-Powered SMS Spam Detector
Problem Statement: Develop a machine learning model to classify SMS messages as
Spam or Ham using Python and Natural Language Processing
techniques. The goal is to build a system that automatically detects spam messages and
evaluates the performance of different machine learning algorithms.
Dataset Description:
1. Dataset Name: SMS Spam Collection Dataset
2. Source: UCI Machine Learning Repository
3. Number of Records: 5572 messages
4. Features:
Column Description
label Spam or Ham
message SMS text
Python Code and Outputs:
1. Data Description
The dataset was loaded using the Pandas library in Python. Basic commands
such as head(), info(), and describe() were used to understand the dataset
structure and preview the SMS messages. The dataset contains two main
columns: label (spam or ham) and message (text of the SMS).
Code & Output:
2. Data Cleaning / Pre-processing
Data preprocessing was performed to prepare the dataset for machine learning.
The steps included:
• Removing unnecessary columns
• Renaming columns for clarity
• Converting categorical labels into numerical values
• Ham → 0
• Spam → 1
• Converting text messages into numerical features using TF-IDF
Vectorizer
Code & Output:
3. Exploratory Data Analysis
Exploratory Data Analysis (EDA) was performed to understand the distribution
of spam and ham messages. Visualization techniques such as pie charts, bar
charts, and line graphs were used to analyze message patterns and spam
frequency.
4. Handling Class Imbalance
The dataset contains more ham messages than spam messages. However, the
imbalance is manageable and the selected model performs well without
additional balancing techniques.
Code & Output:
5. Train-Test Split
The dataset was divided into training and testing sets to evaluate model
performance.
• Training Data → 80%
• Testing Data → 20%
Code & Output:
6. Machine Learning Models Applied
The project uses Multinomial Naïve Bayes, a popular algorithm for text
classification tasks such as spam detection.
Code & Output:
7. Model Evaluation
The model performance was evaluated using metrics such as Accuracy,
Precision, Recall, and F1-score.
Code & Output:
Conclusion: In this project, a machine learning based SMS spam detection system was
developed using Python and Natural Language Processing techniques.
The dataset was preprocessed and converted into numerical features using TF-IDF
vectorization, and a Multinomial Naïve Bayes classifier was applied for message
classification. The model was trained and tested using an 80–20 train-test split and
achieved an accuracy of approximately 96%, indicating good performance in
identifying spam messages. The results show that the Naïve Bayes algorithm is highly
effective for text classification tasks such as spam detection.
Thus, the developed system can successfully classify SMS messages as Spam or Ham,
helping improve communication security and reduce unwanted messages.