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.
- 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.
- 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.
- 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."
The project utilizes a Layered Architecture:
- Input Layer: Raw text string.
- Preprocessing Layer: Tokenization and vectorization.
- Neural Layer (Logistic Regression): Computes a statistical probability .
- Fuzzy Layer (Mamdani Inference): Maps to linguistic labels (Low, Medium, High).
- Output Layer: JSON response (Online) or Console output (Offline).
The logic follows this step-by-step guideline:
- START
- Receive Input Text.
- Apply Preprocessing (Clean/Tokenize).
- Neuro Step: Calculate probability using Logistic Regression ().
- Fuzzy Step: Pass into Membership Functions:
- : Degree of membership in "Ham".
- : Degree of membership in "Uncertainty".
- : Degree of membership in "Spam".
- Inference: Apply Fuzzy Rules (IF probability is HIGH THEN result is SPAM).
- Defuzzification: Calculate the Centroid to find the final decision score.
- Output Result.
- END
# 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
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
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
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
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.