This project implements an end-to-end MLOps pipeline for predicting employee attrition using machine learning. It demonstrates best practices in version control, experiment tracking, automated testing, CI/CD, and drift monitoring.
The dataset used is the IBM HR Analytics Employee Attrition & Performance dataset from Kaggle. It contains employee information and whether they left the company (attrition).
- Source: Kaggle - IBM HR Analytics Employee Attrition & Performance
- Task: Binary classification (predict attrition: Yes/No)
- Features: 34 features including demographic, job-related, and satisfaction metrics
- Rows: 1,470
.
├── configs/
│ └── config.yaml # Configuration file for hyperparameters and paths
├── data/
│ ├── employee_attrition.csv # Raw dataset (tracked with DVC)
│ └── employee_attrition.csv.dvc # DVC pointer file
├── src/
│ ├── __init__.py
│ ├── data_preprocessing.py # Data loading and preprocessing
│ ├── model_training.py # Model training and MLflow logging
│ ├── evaluation.py # Shared evaluation metrics and reports
│ ├── train.py # Main training orchestration script
│ ├── monitor_drift.py # Drift monitoring with Evidently
│ └── utils.py # Utility functions
├── tests/
│ ├── __init__.py
│ ├── test_data_preprocessing.py
│ └── test_data_validation.py # Data and model validation tests
├── reports/ # Drift monitoring reports
├── .github/
│ └── workflows/
│ └── ci-cd.yml # GitHub Actions CI/CD pipeline
├── models/ # Trained models (ignored by git)
├── mlruns/ # MLflow experiment runs (ignored by git)
├── compare_experiments.py # Experiment comparison script
├── run_experiments.py # Multiple experiments runner
├── requirements.txt # Python dependencies
├── .gitignore # Git ignore rules
├── .dvc/ # DVC configuration
├── README.md # This file
├── MONITORING.md # Drift monitoring analysis
└── dvc.yaml # DVC pipeline configuration
- Python 3.9+ (CI uses 3.9; local dev tested with Python 3.12)
- Git
- pip
-
Clone the repository:
git clone https://github.com/arushib11/employee_attrition.git cd employee_attrition -
Create a virtual environment (recommended):
python3 -m venv .venv source .venv/bin/activate python -m pip install -U pip -
Install Python dependencies:
pip install -r requirements.txt
-
Set up DVC and pull data:
# Pull the dataset # If your DVC remote is a public S3 bucket, use unsigned requests: AWS_NO_SIGN_REQUEST=1 dvc pull
Notes:
- This project uses a public S3-backed DVC remote. You should not need AWS credentials to pull data.
- DVC S3 support is included in
requirements.txt. You should not need extra installs beyondpip install -r requirements.txt.
-
Optional: MLflow UI (for experiment tracking):
# Start the UI (use python -m mlflow to ensure you use the venv's mlflow) python -m mlflow ui --backend-store-uri "file:$(pwd)/mlruns"
Single training run:
PYTHONPATH=$PWD/src python src/train.pyRun multiple experiments (recommended for comparison):
python run_experiments.pyCompare experiments (after running multiple experiments):
python compare_experiments.pyRun the full test suite:
PYTHONPATH=$PWD/src pytest tests/ -vRun with coverage:
pytest tests/ --cov=src --cov-report=htmlMonitor for data drift:
python src/monitor_drift.pyThis will:
- Compare reference (training) data vs simulated production data
- Generate an HTML report in
reports/drift_report.html - Exit with code 1 if drift exceeds threshold
Modify configs/config.yaml to change:
- Model hyperparameters (n_estimators, max_depth)
- File paths and data settings
- Training parameters (test_size, random_state)
- Performance thresholds
Example configuration:
data:
raw_path: "data/employee_attrition.csv"
missing_percentage: 0.1
model:
type: "random_forest"
hyperparameters:
n_estimators: 100
max_depth: 10
random_state: 42
training:
test_size: 0.2
random_state: 42
thresholds:
min_accuracy: 0.75
min_f1: 0.70- Git: Code versioning and collaboration
- DVC: Data versioning and pipeline tracking
- Remote Storage: Public S3 bucket (used by graders to
dvc pull)
- Automatic Logging: Hyperparameters, metrics, and models
- Experiment Comparison: Query and compare multiple runs
- Model Registry: Store and version trained models
- Unit Tests: 8 tests for preprocessing functions
- Data Validation: 4 tests for dataset quality
- Model Validation: 2 tests for model performance
- 16 total tests covering all critical functionality
- Test Job: Runs on every push/PR to main
- Training Job: Runs after tests pass, validates model performance
- Automated Quality Gates: Prevents poor models from deployment
- Reference vs Production: Compares data distributions
- Feature-level Analysis: Identifies which features drifted
- HTML Reports: Visual drift detection reports
- Automated Alerts: Fails pipeline when drift exceeds threshold
- Make Changes: Modify code, configs, or add features
- Run Tests:
pytest tests/to ensure nothing breaks - Train Model:
python src/train.pyto validate changes - Commit & Push: GitHub Actions will run CI/CD automatically
- Monitor Drift:
python src/monitor_drift.pyregularly
- Modular Architecture: Separated concerns (preprocessing, training, monitoring)
- Configuration-Driven: All settings in YAML files
- Comprehensive Testing: 16 tests covering unit, data, and model validation
- Experiment Tracking: Compare multiple model configurations
- Data Versioning: DVC tracks dataset changes
- Drift Detection: Automated monitoring for production data changes
- CI/CD Ready: Automated testing and training validation
Current model performance (Random Forest):
- Accuracy: ~87%
- Precision: ~84%
- Recall: ~55%
- F1-Score: ~67%
Note: Performance may vary with different configurations and random seeds.
DVC Pull Fails:
# Check DVC remote configuration
dvc remote list
# Reconfigure remote if needed
dvc remote add -d myremote /path/to/remote
dvc pushMLflow shows no runs:
- Make sure you ran training with MLflow installed (it should print
✅ Experiment logged successfully) - Start the UI from the project root and point it to this repo's
mlruns/:python -m mlflow ui --backend-store-uri "file:$(pwd)/mlruns" - If port 5000 is busy, use
--port 5001
pip install -r requirements.txt fails on macOS / Python 3.12+:
- Recreate the venv and re-run install. This repo pins versions with wheels for Python 3.12.
Tests Fail:
# Run specific test
pytest tests/test_data_preprocessing.py::test_load_data -v
# Debug with print statements
pytest tests/ -sDrift Monitoring Fails:
- Install Evidently:
pip install evidently - Check that reports/ directory exists
- Fork the repository
- Create a feature branch
- Make changes with tests
- Ensure CI/CD passes
- Submit a pull request
This project is for educational purposes as part of the TripleTen MLOps sprint.