Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Design and Implementation of a Spam Classification System Using a Hybrid Neuro‑Fuzzy Approach

1. Project Overview

This project addresses the challenge of electronic spam detection by combining the statistical power of Neural-based learning (Logistic Regression) with the human-like reasoning of Fuzzy Logic. By integrating these two paradigms, the system provides a nuanced classification that identifies not just "Spam" and "Ham," but also "Suspicious" messages that fall into regions of high uncertainty.


2. Requirements Specification

2.1 Hardware Requirements

  • Processor: Intel Core i3 or equivalent (minimum); Intel Core i5 or higher (recommended).
  • RAM: 4GB (minimum); 8GB (recommended for model training).
  • Storage: 500MB of free disk space (includes dataset and serialized model files).
  • Internet Connection: Required for initial dataset download and API testing.

2.2 Software Requirements

  • Operating System: Windows 10/11, macOS, or Linux.
  • Environment: Python 3.10 or 3.13.
  • Libraries:
  • scikit-learn: Feature extraction (TF-IDF) and Neuro-modeling.
  • scikit-fuzzy: Fuzzy Inference System (FIS) development.
  • Flask: Web API implementation.
  • pandas/numpy: Data manipulation.
  • joblib: Model serialization and persistence.

3. Functional Requirements

  • FR-1: Data Acquisition: The system shall automatically download and clean the UCI SMS Spam dataset.
  • FR-2: Text Preprocessing: The system shall normalize text (lowercase, regex URL removal, punctuation stripping).
  • FR-3: Feature Extraction: The system shall convert text into numerical vectors using TF-IDF.
  • FR-4: Hybrid Classification: The system shall generate a probability score (Neuro) and interpret it via fuzzy membership functions (Fuzzy).
  • FR-5: REST API: The system shall provide an endpoint (/predict) to accept text and return JSON results.
  • FR-6: Uncertainty Handling: The system must identify and label messages with medium probability as "Suspicious."

4. Architectural Design

The project utilizes a Layered Architecture:

  1. Input Layer: Raw text string.
  2. Preprocessing Layer: Tokenization and vectorization.
  3. Neural Layer (Logistic Regression): Computes a statistical probability .
  4. Fuzzy Layer (Mamdani Inference): Maps to linguistic labels (Low, Medium, High).
  5. Output Layer: JSON response (Online) or Console output (Offline).

5. System Flowchart (The Hybrid Approach)

The logic follows this step-by-step guideline:

  1. START
  2. Receive Input Text.
  3. Apply Preprocessing (Clean/Tokenize).
  4. Neuro Step: Calculate probability using Logistic Regression ().
  5. Fuzzy Step: Pass into Membership Functions:
  • : Degree of membership in "Ham".
  • : Degree of membership in "Uncertainty".
  • : Degree of membership in "Spam".
  1. Inference: Apply Fuzzy Rules (IF probability is HIGH THEN result is SPAM).
  2. Defuzzification: Calculate the Centroid to find the final decision score.
  3. Output Result.
  4. END

6. Installation and Setup

6.1 Clone and Environment Setup

# Clone the repository
git clone https://github.com/yourusername/spam-neurofuzzy.git
cd spam-neurofuzzy

# Install dependencies
pip install pandas numpy scikit-learn scikit-fuzzy networkx flask joblib requests

6.2 Data and Model Initialization

Run these scripts in order to build the "brain" of the system:

# 1. Download data
python -m src.data_loader

# 2. Preprocess and Extract Features
python run_preprocessing.py

# 3. Train Neuro Layer
python -m src.train_logistic

# 4. Train Fuzzy Layer
python -m src.train_anfis

6.3 Running the System

Option A: Online (Web API)

python api/app.py
  • Test in browser: http://127.0.0.1:5000/predict?text=Win+money+now

Option B: Offline (CLI)

python -m src.predict

7. Folder Structure

spam-neurofuzzy/
├── api/                # Flask API (Online)
├── data/               # CSV datasets (Raw and Processed)
├── models/             # Serialized .pkl model files
├── src/                # Core logic (Preprocess, Train, Predict)
├── requirements.txt    # Dependency list
├── test_api.py         # Automated API testing script
└── README.md           # Project Documentation


8. Conclusion

This hybrid system demonstrates that AI can be both powerful and interpretable. By using Fuzzy Logic as a decision-making layer, we mitigate the risk of binary errors and provide a transparent confidence-based approach to spam detection.

About

This project implements an intelligent spam filter that combines the statistical learning of a Neural component (Logistic Regression) with the linguistic reasoning of Fuzzy Logic.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages