AWS Deployed

Spam Mail
Classification

An end-to-end Deep Learning project that filters inbox clutter with 98.17% accuracy. From SMOTE balancing to AWS deployment.

Kaggle
01

The Inbox Clutter

Why do we need a robust classifier?

"I have no cloud computing skills," they say. But insights from the top 1% highlight that ML extends far beyond Jupyter Notebooks. Building the model is just 10% of the journey.

  • Security Risk

    Phishing and scams lurk in seemingly innocent emails.

  • Productivity

    Filtering out noise allows users to focus on what matters.

  • Deployment

    Moving from notebook to a live AWS EC2 instance.

Spam vs. Ham

SPAM

"Congratulations! You've won a $1,000 gift card. Click here to claim your prize immediately!"

HAM

"Hey, just checking in on the project status. Let's sync up tomorrow at 10 AM."

02

The Experiment

Fighting imbalance with SMOTE and Deep Learning.

Data & Justice
Using SMOTE to fix class imbalance

"As an aspiring Data Scientist, it’s appalling how much injustice is lurking in this data. Look at how ‘ham’ is dominating ‘spam’! 😱 I put my hands in my pocket and bring out the weapon for justice… SMOTE!!!"

BEFORE SMOTE
AFTER SMOTE

The Neural Network

Input (CountVectorizer)Sparse Matrix
Dense Layer (ReLU)64 Neurons
Dropout0.7
Dense Layer (ReLU)32 Neurons
Output Layer (Sigmoid)Binary Class

Accuracy

98.17%

F1 Score: 0.9840

Keras Model
model = Sequential()
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.7))
model.add(Dense(32, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

model.compile(
  optimizer='adam', 
  loss='binary_crossentropy'
)
03

The Pipeline

From raw CSV to a deployed Streamlit application.

01

STEP 01

Cleaning

Drop duplicates & Handle Nulls

02

STEP 02

EDA

Visualize Class Imbalance

03

STEP 03

SMOTE

Synthetic Minority Over-sampling

04

STEP 04

Training

Train Neural Network

05

STEP 05

Saving

Dump Model & Vectorizer

04

The Launch

Deploying to AWS EC2 with a custom bash script.

AWS EC2 Instance

Launched an Ubuntu instance and configured Security Groups to expose port 8501 for Streamlit.

Automated Script

Wrote `deploy.sh` to handle updates, dependencies, virtual environments, and systemd service creation automatically.

Systemd Service

Ensures the app runs in the background and restarts automatically on failure or reboot.

ubuntu@ip-172-31-0-0:~/Spam-email
# deploy.sh snippet
$ sudo apt install -y python3-pip python3-venv git
$ git clone -b Deployment https://github.com/Harshithvarma007/Spam-email.git
# Creating systemd service...
[Unit]
Description=Streamlit Web Application
[Service]
ExecStart=$(pwd)/venv/bin/streamlit run app.py
Restart=always
$ sudo systemctl enable streamlit
Streamlit service started on port 8501
_
05

Live Demo

Test the deployed model (Simulation).

Live Demo In Progress

We are currently fine-tuning the serving infrastructure on AWS. The live interface will be available soon.

SPAM
Confidence: 99.8%