A Python library for detecting spam messages using machine learning. Install it, pass in text, get a prediction.
pip install pyspamdetector
from pyspamdetector import PySpamDetector
detector = PySpamDetector()
# Classify a message
is_spam = detector.readText("Congratulations, you've won a $1000 gift card! Click here to claim your prize.")
print(is_spam) # True
Classifies a message as spam or not.
- Returns: True if spam, False if not.
Returns a dictionary with the classification result and a human-readable advice string.
detector.describeText("Congratulations, you've won a $1000 gift card! Click here to claim your prize.")
# Returns:
{
"message": "Congratulations, you've won a $1000 gift card! Click here to claim your prize.",
"classification": "Spam",
"advice": "Be cautious! This message appears to be spam. Avoid clicking on links or providing sensitive information."
}
pyspamdetector uses a Logistic Regression classifier trained on TF-IDF features extracted from text messages. The model ships pre-trained with the package, so there's nothing to train yourself. Just install and use.
Evaluated on a held-out test set:
| Metric | Score |
|---|---|
| Test accuracy | 96.6% |
| Training accuracy | 96.7% |
The near-identical train and test accuracy indicates the model generalizes well without overfitting.
- Classifier: Logistic Regression (scikit-learn)
- Features: TF-IDF vectorization
- Dataset: A public spam message dataset
The full training notebook is publicly available on Kaggle: Spam Model notebook.
- Python 3.0+
- scikit-learn
Released under the GNU General Public License v3.0. See LICENSE for details.
Pull requests are welcome. For major changes, please open an issue first to discuss what you'd like to change.
Built by Praise Chiedozie Sunday.
- Portfolio: praise-chiedozie-sunday.vercel.app
- LinkedIn: praise-sunday
- GitHub: @Psunday2000
If you find this package useful, a star on GitHub is appreciated.