An end-to-end Machine Learning project that predicts student's math score based on various demographic and academic features. Built with MLOps principles, this project demonstrates a complete ML pipeline with proper logging, exception handling, and experiment tracking.
This project predicts students' math scores using features such as:
- Gender
- Race/Ethnicity
- Parental Level of Education
- Lunch Type
- Test Preparation Course
- Reading Score (out of 100)
- Writing Score (out of 100)
The project follows MLOps best practices including:
- β Modular code structure
- β Comprehensive logging
- β Exception handling
- β Multiple algorithm comparison
- β Hyperparameter tuning
- β Experiment tracking with MLflow & DagsHub
- β Data version control with DVC
- β CI/CD ready pipeline
student-exam-performance-predictor/
β
βββ .github/
β βββ workflows/
β βββ ci-cd.yml # CI/CD pipeline configuration
β
βββ .dvc/ # DVC configuration
β
βββ artifacts/ # All artifacts generated
β βββ data.csv # Cleaned dataset
β βββ train.csv # Training data
β βββ test.csv # Test data
β βββ model.pkl # Best model pickle file
β βββ preprocessor.pkl # Preprocessor object
β βββ model_monitoring/ # Model performance metrics
β
βββ config/
β βββ config.yaml # Configuration file
β
βββ data/
β βββ raw/ # Raw data (DVC tracked)
β βββ processed/ # Processed data
β
βββ logs/
β βββ app.log # Application logs
β βββ data_ingestion.log
β βββ data_transformation.log
β βββ model_trainer.log
β βββ prediction.log
β
βββ mlruns/ # MLflow runs
β
βββ notebooks/
β βββ 01_data_exploration.ipynb
β βββ 02_model_training.ipynb
β βββ 03_model_evaluation.ipynb
β
βββ src/ML_Ops_Project
β βββ __init__.py
β β
β βββ components/
β β βββ __init__.py
β β βββ data_ingestion.py # Data ingestion component
β β βββ data_transformation.py # Data preprocessing
β β βββ model_trainer.py # Model training & tuning
β β βββ model_monitoring.py # Model performance tracking
β β
β βββ pipeline/
β β βββ __init__.py
β β βββ training_pipeline.py # End-to-end training pipeline
β β βββ prediction_pipeline.py # Prediction pipeline
β β
β βββ logger.py # Logging configuration
β βββ exception.py # Custom exception handling
β βββ utils.py # Utility functions
β
βββ templates/
β βββ index.html # Landing page
β βββ home.html # Prediction form page
β
βββ static/
β βββ css/
β βββ style.css # Custom CSS styles
β
βββ .dvcignore
βββ .gitignore
βββ .env.example # Environment variables template
βββ requirements.txt # Project dependencies
βββ setup.py # Package setup
βββ app.py # Flask application entry point
βββ dvc.yaml # DVC pipeline configuration
βββ dvc.lock # DVC lock file
βββ mlflow_tracking.py # MLflow experiment tracking
βββ README.md # Project documentation
βββ LICENSE
- Python 3.8+: Primary programming language
- Flask: Web framework for API and UI
- Scikit-learn: Machine learning library
- Pandas & NumPy: Data manipulation
- Matplotlib & Seaborn: Visualization
- MLflow: Experiment tracking and model registry
- DagsHub: Centralized ML platform (MLflow + DVC)
- DVC (Data Version Control): Data versioning and pipeline
- Git: Version control
- Jupyter Lab: Interactive development
- VS Code: IDE (recommended)
- GitHub Actions: CI/CD
The modern, Material Design-inspired landing page with navigation to the prediction form
User-friendly form interface for inputting student data
-
Python 3.8 or higher
python --version
-
Git
git --version
-
DVC
pip install dvc
-
DagsHub Account (for experiment tracking)
- Sign up at dagshub.com
-
Clone the repository
git clone https://github.com/yourusername/student-exam-performance-predictor.git cd student-exam-performance-predictor -
Create and activate virtual environment
# Windows python -m venv venv venv\Scripts\activate # Mac/Linux python3 -m venv venv source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Install the package in development mode
pip install -e . -
Set up environment variables
cp .env.example .env # Edit .env with your DagsHub credentials -
Set up DVC remote storage
dvc remote add -d origin https://dagshub.com/yourusername/student-exam-performance-predictor.dvc dvc remote modify origin --local auth basic dvc remote modify origin --local user your_username dvc remote modify origin --local password your_token
The project follows a structured ML pipeline with the following stages:
- Loads raw data from CSV files
- Splits data into train/test sets (80/20)
- Saves artifacts for downstream use
- Logs data statistics and validation
Component: src/components/data_ingestion.py
- Handles missing values
- Encodes categorical variables
- Scales numerical features
- Creates preprocessor object
- Saves processed data
Component: src/components/data_transformation.py
- Trains multiple models:
- Linear Regression
- Decision Tree Regressor
- Random Forest Regressor
- Gradient Boosting Regressor
- XGBoost Regressor
- CatBoost Regressor
- AdaBoost Regressor
- K-Neighbors Regressor
- Performs hyperparameter tuning using GridSearchCV
- Evaluates models using multiple metrics (RΒ², MAE, RMSE)
- Logs all experiments with MLflow
- Saves the best model
Component: src/components/model_trainer.py
- Tracks model performance over time
- Logs metrics to MLflow
- Monitors data drift
- Generates performance reports
Component: src/components/model_monitoring.py
- Loads the trained model and preprocessor
- Accepts user inputs via Flask API
- Transforms input data
- Returns predictions with confidence intervals
Component: src/pipeline/prediction_pipeline.py
| Model | Parameters Tuned | Best RΒ² Score |
|---|---|---|
| Linear Regression | - | ~0.88 |
| Decision Tree | max_depth, min_samples_split | ~0.85 |
| Random Forest | n_estimators, max_depth, min_samples_split | ~0.81 |
| Gradient Boosting | n_estimators, learning_rate, max_depth | ~0.82 |
| XGBoost | n_estimators, learning_rate, max_depth, subsample | ~0.83 |
| CatBoost | iterations, depth, learning_rate | ~0.84 |
| AdaBoost | n_estimators, learning_rate | ~0.79 |
| K-Neighbors | n_neighbors, weights, p | ~0.81 |
Note: Actual scores may vary based on data split and tuning configuration.
This project uses MLflow integrated with DagsHub for experiment tracking:
-
Start MLflow UI locally:
mlflow ui --backend-store-uri mlruns/
-
View experiments on DagsHub:
- Navigate to your DagsHub repository
- Click on "Experiments" tab
- View all runs, metrics, and parameters
-
Log experiments programmatically:
import mlflow with mlflow.start_run(): mlflow.log_param("model_type", "RandomForest") mlflow.log_metric("r2_score", 0.92) mlflow.sklearn.log_model(model, "model")
# Run full training pipeline
python src/pipeline/training_pipeline.py
# Or run components individually
python src/components/data_ingestion.py
python src/components/data_transformation.py
python src/components/model_trainer.py# Start Flask application
python app.py
# Access the application
# Open browser and go to: http://localhost:5000# Example API call
import requests
data = {
"gender": "male",
"ethnicity": "group A",
"parental_level_education": "bachelor's degree",
"lunch": "standard",
"test_preparation_course": "completed",
"reading_score": 85,
"writing_score": 78
}
response = requests.post("http://localhost:5000/predict", json=data)
print(response.json())The project implements comprehensive logging using Python's built-in logging module:
from src.utils.logger import logging
logging.info("Model training started")
logging.error("Error occurred during prediction")logs/app.log: General application logslogs/data_ingestion.log: Data ingestion specific logslogs/data_transformation.log: Transformation logslogs/model_trainer.log: Training logslogs/prediction.log: Prediction pipeline logs
Custom exception handling with detailed error messages:
from src.utils.exception import CustomException
try:
# Some operation
pass
except Exception as e:
raise CustomException(e, sys)data:
raw_data_path: data/raw/student_performance.csv
train_data_path: artifacts/train.csv
test_data_path: artifacts/test.csv
model:
random_state: 42
test_size: 0.2
logging:
level: INFO
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
mlflow:
tracking_uri: "https://dagshub.com/yourusername/student-exam-performance-predictor.mlflow"
experiment_name: "Student_Exam_Performance"Run tests using pytest:
pytest tests/Test coverage:
pytest --cov=src tests/The DVC pipeline is defined in dvc.yaml:
stages:
data_ingestion:
cmd: python src/components/data_ingestion.py
deps:
- data/raw/student_performance.csv
- src/components/data_ingestion.py
outs:
- artifacts/train.csv
- artifacts/test.csv
data_transformation:
cmd: python src/components/data_transformation.py
deps:
- artifacts/train.csv
- artifacts/test.csv
- src/components/data_transformation.py
outs:
- artifacts/preprocessor.pkl
model_trainer:
cmd: python src/components/model_trainer.py
deps:
- artifacts/train.csv
- artifacts/test.csv
- artifacts/preprocessor.pkl
- src/components/model_trainer.py
outs:
- artifacts/model.pklRun DVC pipeline:
dvc reproThe project includes GitHub Actions workflow (.github/workflows/ci-cd.yml):
name: CI/CD Pipeline
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Run tests
run: |
pytest tests/
- name: Run DVC pipeline
run: |
dvc pull
dvc repro- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Harsh Singh - GitHub Profile
- Data source: Student Performance Dataset
- Inspired by MLOps best practices from various industry sources
For questions or support, please open an issue or contact: ragnar_harsh@yahoo.com
Star β this repository if you find it useful!