A machine learning tool that automatically classifies emails into categories such as "notifications" and "correspondence" based on their content and metadata.
- Training: Train the classifier using your own categorized emails
- Evaluation: Evaluate the classifier's performance with test data
- Classification: Classify new emails automatically
- Model Backups: Automatically creates backups of previous models when training new ones
- Python 3.6 or higher
- pip (Python package installer)
-
Clone the repository:
git clone https://github.com/cpknight/email-classifier.git cd email-classifier -
Install the required dependencies:
pip install pandas scikit-learn nltk
The email classifier script supports three main commands: train, evaluate, and classify.
./email_classifier.py train --dir <training_directory> --output <model_file>Example:
./email_classifier.py train --dir ./emails --output model.pklBy default, the script expects your training data to be organized in two subdirectories:
notifications/: Contains notification-type emailscorrespondence/: Contains correspondence-type emails
When training a new model, if a model already exists at the specified output path, a backup will be created with the original creation timestamp appended to the filename.
./email_classifier.py evaluate --model <model_file> --dir <test_directory>Example:
./email_classifier.py evaluate --model model.pkl --dir ./test_emails./email_classifier.py classify --model <model_file> --email <email_file>Example:
./email_classifier.py classify --model model.pkl --email ./new_email.emlFor training and evaluation, the script expects emails to be organized in directories by category:
training_data/
├── correspondence/
│ ├── email1.eml
│ ├── email2.eml
│ └── ...
└── notifications/
├── email1.eml
├── email2.eml
└── ...
Each .eml file should be a standard email file with headers and content.
When training a new model, if a model already exists at the specified location, the script automatically creates a backup of the existing model before overwriting it. The backup filename includes the original creation timestamp in the format:
model.pkl.YYYYMMDD_HHMMSS.bak
This feature ensures you never lose previous model versions and can track model evolution over time.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Created by cpknight ... I can't take credit. Claude 3.7 sonnet by way of Warp wrote it - this is another AI-generated project!