← Back to list

E-mail Classification NLP

The classification project for spam e-mail detection is taken from dataset kaggle.

Taner Ant · 2022-08-16 15:51 · 0 claps · 1.5 min read
#nlp #tokenization #nltk #word-cloud #spam
Open on Medium ↗
Wiki topics: ML · Machine Learning

E-mail Classification NLP

The classification project for spam e-mail detection is taken from dataset kaggle.

EDA

Tokenization, turning a string or document into tokens (smaller chunks).

word_tokens = [word_tokenize(mesaage) for mesaage in df.Message_body]
print(word_tokens[0])

len_tokens = []

for i in range(len(word_tokens)):
     len_tokens.append(len(word_tokens[i]))

df['n_words'] = len_tokens 

Word count distribution plot by target value

Wordcloud

Model

I used StratifiedKFold for train test split , then convert text to matrix of TF-IDF features with TfidfVectorizer.

Finally, I created a model with MultinomialNB.

TF-IDF (term frequency-inverse document frequency) is a statistical measure that evaluates how relevant a word is to a document in a collection of documents.

max_df = 0.70 means "ignore terms that appear in more than 70% of the documents".

Result

Resources

[embed]NLP/Email_text_classification.ipynb at main · tanerant/NLP Contribute to tanerant/NLP development by creating an account on GitHub.github.com

[embed]E-Mail classification NLP Text classification datawww.kaggle.com

https://www.nltk.org/


메타데이터
post_id
d7d7dfd76d8e
slug
e-mail-classification-nlp-d7d7dfd76d8e
url
https://medium.com/@tanerant/e-mail-classification-nlp-d7d7dfd76d8e
canonical_url
https://medium.com/@tanerant/e-mail-classification-nlp-d7d7dfd76d8e
author_url
https://medium.com/@tanerant
status
ok
fetched_at
2026-07-26 18:43:57