Downloads · 30 days
0
satyam2025/spam-email-classifier
spam-email-classifier is a text classification model from satyam2025. Use it when you need a label for a piece of text. It is set up for sklearn. The card lists the license as mit.
This model classifies emails as spam or ham (legitimate) with 96%+ accuracy.
Downloads · 30 days
0
Access
Public
Updated Nov 11, 2025
Repo size
303 MB
Likes
0
Public
Click a slice to open those files.
.pkl303 MB · 100%
From the Hugging Face model README
This model classifies emails as spam or ham (legitimate) with 96%+ accuracy.
spam_classifier_model.pkl - Trained classification modeltfidf_vectorizer.pkl - TF-IDF vectorizer (required for inference)from huggingface_hub import hf_hub_download
import pickle
import re
# Download model and vectorizer
model_path = hf_hub_download(
repo_id="satyam2025/spam-email-classifier",
filename="spam_classifier_model.pkl"
)
vectorizer_path = hf_hub_download(
repo_id="satyam2025/spam-email-classifier",
filename="tfidf_vectorizer.pkl"
)
# Load files
with open(model_path, 'rb') as f:
model = pickle.load(f)
with open(vectorizer_path, 'rb') as f:
vectorizer = pickle.load(f)
# Preprocessing function
def clean_email_text(text):
text = text.lower()
text = re.sub(r'\S*@\S*\s?', '', text)
text = re.sub(r'http\S+|www\.\S+', '', text)
text = re.sub(r'<.*?>', '', text)
text = re.sub(r'[^a-zA-Z\s!?.]', ' ', text)
text = ' '.join(text.split())
return text
# Predict function
def predict_spam(email_text, threshold=0.8):
cleaned = clean_email_text(email_text)
features = vectorizer.transform([cleaned])
spam_probability = model.predict_proba(features)[0][1]
is_spam = spam_probability >= threshold
return {
'spam_probability': spam_probability,
'is_spam': is_spam,
'classification': 'SPAM' if is_spam else 'HAM'
}
# Example
email = "Congratulations! You won $1000. Click here now!"
result = predict_spam(email)
print(result)
# Output: {'spam_probability': 0.966, 'is_spam': True, 'classification': 'SPAM'}
.pkl files for inference@misc{spam-classifier-2024,
author = {Satyam},
title = {Spam Email Classifier},
year = {2024},
publisher = {HuggingFace},
howpublished = {\url{https://huggingface.co/satyam2025/spam-email-classifier}}
}
MIT License