</>
ShikshaCSLearn. Code. Grow.
๐Ÿ”
โ˜• Support Us
ShikshaCSโ€บMini Projects
ML

Basic Spam Email Classifier

Machine LearningAdvanced
Pythonscikit-learn

๐Ÿ’ก Overview

This is a classic 'hello world' of machine learning โ€” a perfect first project because the whole pipeline (data โ†’ features โ†’ model โ†’ prediction) fits in under 50 lines of Python.

โœ… Features to Build

0/4 done

๐Ÿงญ Step-by-Step Guide

1

Find a small public spam dataset (e.g. the classic SMS Spam Collection dataset) as a CSV.

2

Load it with pandas, and split it into training and testing sets.

3

Convert the raw text into numeric features using CountVectorizer or TfidfVectorizer from scikit-learn.

4

Train a simple model โ€” Naive Bayes (MultinomialNB) works great and trains almost instantly for this task.

5

Predict on the test set and print the accuracy score to see how well it performs.

๐Ÿš€ Starter Code

from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(emails, labels, test_size=0.2)
vectorizer = CountVectorizer()
X_train_vec = vectorizer.fit_transform(X_train)
model = MultinomialNB()
model.fit(X_train_vec, y_train)

๐Ÿ’ก Pro Tip

Don't worry about achieving a 'perfect' model โ€” even 90% accuracy on your first attempt is a genuine win. The goal here is understanding the pipeline, not building a production spam filter.

โ† Back to all Projects