📘 Lesson · Lesson 94
Email Spam Detection
Email Spam Detection
About this Project
💡 At a Glance
This project classifies messages as spam or not spam using a Naive Bayes model on text.
The Program
Python
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
texts = ["win money now", "meeting at office", "free lottery prize", "project deadline today"]
labels = ["spam", "ham", "spam", "ham"]
vec = CountVectorizer()
X = vec.fit_transform(texts)
model = MultinomialNB()
model.fit(X, labels)
test = vec.transform(["win free prize"])
print("Prediction:", model.predict(test)[0])Prediction: spam
How it Works
- CountVectorizer turns text into word-count numbers.
- Naive Bayes learns which words appear in spam vs ham, then predicts.
Summary
- Convert text to numbers, train Naive Bayes, then predict spam/ham.
- A practical introduction to text classification.
इस Project के बारे में
💡 एक नज़र में
यह project text पर Naive Bayes model से messages को spam या not spam classify करता है।
Program
Python
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
texts = ["win money now", "meeting at office", "free lottery prize", "project deadline today"]
labels = ["spam", "ham", "spam", "ham"]
vec = CountVectorizer()
X = vec.fit_transform(texts)
model = MultinomialNB()
model.fit(X, labels)
test = vec.transform(["win free prize"])
print("Prediction:", model.predict(test)[0])Prediction: spam
कैसे काम करता है
- CountVectorizer text को word-count numbers बनाता है।
- Naive Bayes सीखता है कौन से words spam बनाम ham में आते हैं, फिर predict करता है।
सारांश
- Text को numbers बनाएं, Naive Bayes train करें, फिर spam/ham predict करें।
- Text classification का practical परिचय।