DEV Community

Alen Kurian
Alen Kurian

Posted on

Building a Spam Classifier using Machine Learning and Flask

Recently, I built a small project where I created a spam classifier that can detect whether a message is spam or not.

This is part of my learning journey in Artificial Intelligence and Machine Learning, and I wanted to build something practical instead of just reading theory.

๐Ÿ’ก Why I Built This

While learning machine learning, I understood that just watching tutorials is not enough. The best way to learn is by building projects.

Spam detection is something we see in real life (emails, messages, etc.), so I thought it would be a good project to start with.

๐Ÿš€ What This Project Does

The application takes a text message as input and tells whether it is:

Spam

Not Spam

Example:

Input:

You have won a free iPhone!

Output:

Spam (Confidence: 99%)
๐Ÿง  How It Works (Simple Explanation)

I used a basic machine learning pipeline:

Clean the text (remove unwanted words and symbols)

Convert text into numbers using TF-IDF

Train a Naive Bayes model

Use the trained model to predict new inputs

๐Ÿ›  Tech Stack

Python

scikit-learn

pandas

nltk

Flask

HTML, CSS, JavaScript

โš™๏ธ Project Structure

The project is divided into different parts:

preprocessing.py โ†’ cleans the text

train.py โ†’ trains the model

predict.py โ†’ predicts from command line

app.py โ†’ Flask backend

index.html โ†’ frontend

๐ŸŒ How the Web App Works

User enters a message

Frontend sends request to Flask

Backend processes the text

Model predicts the result

Result is shown instantly

๐Ÿงช What I Learned

From this project, I understood:

how NLP works at a basic level

how machine learning models are trained

how to connect ML with a web application

how to create a simple API using Flask

This was my first time building a full project from start to end, and it helped me understand things much better.

๐Ÿ”— GitHub

You can check out the project here:

https://github.com/alenkurian-ml/spam-classifier

๐Ÿ“Œ Final Thoughts

This is a small project, but for me it was an important step in learning AI.

Iโ€™m still learning and building projects step by step. I plan to explore more advanced topics and improve my skills.

If you are also learning machine learning, I would suggest starting with small projects like this.

Thanks for reading ๐Ÿ™‚

Top comments (0)