Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fraud Detection System

A machine learning-powered web application built with Streamlit that classifies emails and SMS messages as spam or legitimate (ham) using natural language processing techniques.

Features

  • Real-time Classification: Instantly classify messages as spam or not spam
  • Text Preprocessing: Advanced NLP preprocessing including tokenization, stemming, and stopword removal
  • Web Interface: User-friendly Streamlit interface for easy message input and classification
  • Machine Learning: Uses pre-trained TF-IDF vectorizer and classification model
  • Interactive UI: Clean and intuitive design with emoji indicators for results

How It Works

  1. Text Preprocessing:

    • Converts text to lowercase
    • Tokenizes the message into individual words
    • Removes non-alphanumeric characters
    • Filters out English stopwords and punctuation
    • Applies Porter Stemming to reduce words to their root forms
  2. Feature Extraction:

    • Uses TF-IDF (Term Frequency-Inverse Document Frequency) vectorization
    • Converts preprocessed text into numerical features
  3. Classification:

    • Applies pre-trained machine learning model
    • Returns binary classification (Spam/Not Spam)

Installation

Prerequisites

  • Python 3.7+
  • pip package manager

Setup Instructions

  1. Clone the repository:
git clone <repository-url>
cd spam-detector
  1. Install dependencies:
pip install -r requirements.txt
  1. Ensure model files are present:

    • vectorizer.pkl - Pre-trained TF-IDF vectorizer
    • model.pkl - Pre-trained classification model
  2. Run the application:

streamlit run app.py
  1. Access the web interface:
    • Open your browser and navigate to http://localhost:8501

Usage

  1. Launch the application using the command above
  2. Enter your email or SMS message in the text input field
  3. Click the "Predict" button
  4. View the classification result:
    • 🚫 Spam: Message classified as spam
    • Not Spam: Message classified as legitimate

Project Structure

spam-detector/
├── app.py              # Main Streamlit application
├── vectorizer.pkl      # Pre-trained TF-IDF vectorizer
├── model.pkl          # Pre-trained classification model
├── requirements.txt   # Python dependencies
└── README.md         # Project documentation

Dependencies

Core Libraries

  • streamlit: Web application framework
  • nltk: Natural language processing toolkit
  • scikit-learn: Machine learning library
  • pandas: Data manipulation and analysis
  • numpy: Numerical computing

NLP Components

  • Porter Stemmer: Word stemming algorithm
  • Stopwords: English stopword corpus
  • Tokenization: Word tokenization tools

Full Requirements

See requirements.txt for complete list of dependencies with versions.

Technical Details

Text Preprocessing Pipeline

def transform_text(text):
    text = text.lower()                    # Lowercase conversion
    text = word_tokenize(text)             # Tokenization
    y = [i for i in text if i.isalnum()]   # Remove non-alphanumeric
    y = [i for i in y if i not in stopwords.words('english')]  # Remove stopwords
    y = [ps.stem(i) for i in y]           # Apply stemming
    return " ".join(y)

Model Architecture

  • Vectorization: TF-IDF (Term Frequency-Inverse Document Frequency)
  • Classification: Binary classification (likely Naive Bayes, SVM, or similar)
  • Output: Binary prediction (0 = Not Spam, 1 = Spam)

Performance Considerations

  • NLTK Downloads: Automatic download of required NLTK corpora
  • Model Loading: Models loaded once at startup for efficiency
  • Preprocessing: Fast text preprocessing pipeline
  • Memory Usage: Models kept in memory for quick predictions

Limitations

  • Language Support: Currently optimized for English text only
  • Model Dependency: Requires pre-trained model files
  • Internet Connection: NLTK may require internet for initial corpus downloads
  • Text Length: Performance may vary with very long messages

Troubleshooting

Common Issues

  1. NLTK Download Errors:
python -c "import nltk; nltk.download('punkt'); nltk.download('stopwords')"
  1. Missing Model Files:

    • Ensure vectorizer.pkl and model.pkl are in the project directory
    • Verify files are not corrupted
  2. Streamlit Port Issues:

streamlit run app.py --server.port 8502

Error Messages

  • File not found: Check if model pickle files exist
  • Import errors: Verify all dependencies are installed
  • NLTK errors: Ensure NLTK data is downloaded correctly

Future Enhancements

  • Multi-language support
  • Confidence score display
  • Batch processing capability
  • Model retraining interface
  • Performance metrics dashboard
  • API endpoint for integration
  • Mobile-responsive design improvements

Model Training

If you need to retrain the model:

  1. Prepare your dataset with labeled spam/ham messages
  2. Use the same preprocessing pipeline (transform_text function)
  3. Train TF-IDF vectorizer and classification model
  4. Save models using pickle for deployment

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

License

This project is for educational and demonstration purposes. Please ensure compliance with relevant data privacy regulations when processing personal messages.


Note: This application is designed for educational purposes and should be thoroughly tested before use in production environments.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages