📘 Lesson  ·  Lesson 94

Email Spam Detection

इस 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 परिचय।
← Back to Python Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.