Basic Spam Email Classifier
๐ก 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
Find a small public spam dataset (e.g. the classic SMS Spam Collection dataset) as a CSV.
Load it with pandas, and split it into training and testing sets.
Convert the raw text into numeric features using CountVectorizer or TfidfVectorizer from scikit-learn.
Train a simple model โ Naive Bayes (MultinomialNB) works great and trains almost instantly for this task.
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.