How rachitnaruzu/mailclassifier works
Project Type and Purpose
• This is a standalone machine-learning pipeline (CLI/tool) for classifying emails into Spam/Ham using Logistic Regression, Feed-forward ANN, and SVM.
• It ingests raw email files, extracts features, builds datasets, trains multiple models, tests them, and generates results + charts.
Top-Level Components
a. Data Stores (raw and processed)
• Raw Emails Store:
• mails/spam/ (all spam emails)
• mails/ham/ (all non-spam emails)
• Feature Store (intermediate): a serialized dataset (e.g., NumPy arrays or pickles) created by create_data.py
• Model Artifacts (optional): saved model parameters or weight files (if persisted)
• Visualization Outputs: images/*.JPG
b. Processing Modules
• extract.py: tokenization, regex filtering, Porter stemming, builds vocabulary (top 400–500 words)
• create_data.py: reads raw emails + vocabulary, produces feature matrix (X) + label vector (y)
• logistic_regression.py: implements LR with regularization using NumPy
• artificial_neural_network.py: implements feed-forward ANN + backprop using NumPy
• SVM modules: calls out to LIBSVM/LIBLINEAR (via sklearn) for linear and Gaussian SVM
• demo.py: orchestration script that invokes data creation, trains all three models, evaluates on test set, prints accuracy, and outputs top predictors
c. Visualization Module
• matplotlib (in scripts) generates cost vs. iteration and hyperparameter curves, saved under images/
Data Flows and Interactions
1. Raw Emails → extract.py → Vocabulary List (400–500 words)
2. Raw Emails + Vocabulary → create_data.py → Feature Matrix + Labels
3. Feature Matrix + Labels → { logistic_regression.py | artificial_neural_network.py | sklearn SVM } → Trained Models + Training Metrics
4. Trained Models + Test Data → demo.py → Validation Metrics + Top Predictors
5. Training/Validation Metrics → matplotlib → Stored Plots in images/
Architectural Patterns & Design Principles
• Pipeline Pattern: sequential data-processing stages
• Separation of Concerns:
• extract.py (feature engineering)
• create_data.py (data preparation)
• modeling scripts (algorithm implementations)
• demo.py (orchestration)
• images/ (presentation)
• Modular CLI utilities, each with a single responsibility
Key Technologies & Libraries
• Python 3.x (language)
• NumPy (matrix operations for LR & ANN)
• NLTK (Porter stemmer)
• sklearn (SVM interface to LIBSVM/LIBLINEAR)
• matplotlib (plotting)
• re (regex filtering)
• SciPy (if needed by matplotlib)
Final Checklist
• [ ] All major scripts/modules labeled
• [ ] Data stores (raw emails, features, model files) clearly shown
• [ ] Third-party libraries called out as dependencies