Skip to content

Navigation Menu

Sign in
Sign up

Repository files navigation

πŸŽ“ Student Performance Predictor β€” End-to-End ML Project

A production-style, refactored & beautified version of the classic "End To End Data Science Project" tutorial. Predicts a student's Math Score from demographic & academic features through a clean modular pipeline and a colorful animated Flask UI.

Python Flask scikit-learn CatBoost XGBoost License Status

Demo Quick Start API Architecture


✨ Highlights

🧠 ML Pipeline

  • πŸ“₯ Data Ingestion β€” Loads stud.csv, persists train/test splits to artifacts/
  • πŸ› οΈ Data Transformation β€” Numerical scaling + categorical one-hot encoding (ColumnTransformer)
  • πŸ§ͺ Model Training β€” GridSearchCV across 8 regressors, best model saved as model.pkl

🎨 Web UI

  • 🌈 Animated gradient background with floating color blobs
  • πŸͺŸ Glassmorphism cards, smooth fade-up & pop animations
  • 🎯 Animated score-meter ring + πŸͺ… confetti on prediction
  • πŸ“± Fully responsive (mobile β†’ desktop)

βš™οΈ Engineering

  • πŸͺ΅ Custom timestamped logger (file + console handlers)
  • 🚨 Custom exception class with file & line number
  • πŸ’Ύ Pickled artifacts via dill
  • 🧱 setup.py based packaging (-e . install)

πŸ”Œ API Endpoints

  • GET / β€” Landing page
  • GET|POST /predictdata β€” Predict math score
  • GET /health β€” JSON health & artifact check

πŸ“Έ Demo

Landing Page Predict Page


🧩 Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Data Source │──▢ β”‚ Data Ingestion │──▢ β”‚ Data Transformationβ”‚
β”‚ stud.csv β”‚ β”‚ (src/components) β”‚ β”‚ (ColumnTransformer)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 β”‚
 β–Ό
 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 β”‚ Flask Web App │◀── β”‚ Model Trainer β”‚
 β”‚ (templates + UI) β”‚ β”‚ (GridSearchCV x8) β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Pick one workflow that fits your machine. Do not create both a Conda environment and a standard Python venv in the same venv directory.


πŸͺŸ Option A β€” Conda (Windows-friendly, prefix env)

:: 1) Open the project in VS Code
code .
:: 2) Create a local Conda env (prefix style, no global registration)
conda create -p venv python==3.8 -y
:: 3) (One-time) enable 'conda activate' in cmd
conda init
:: **Close & reopen your terminal** so the changes take effect.
:: 4) Activate the env
conda activate .\venv
:: 5) Install local training dependencies + editable package
pip install -r requirements-training.txt
pip install -e .

πŸ’‘ Conda must be installed and available in the terminal. A trailing \ is not required when activating a prefix environment.


🐍 Option B β€” venv (built-in, no Conda)

Windows PowerShell:

python -m venv venv
.\venv\Scripts\Activate.ps1
pip install -r requirements-training.txt
pip install -e .

Windows Command Prompt:

python -m venv venv
venv\Scripts\activate.bat
pip install -r requirements-training.txt
pip install -e .

Windows Git Bash:

python -m venv venv
source venv/Scripts/activate
pip install -r requirements-training.txt
pip install -e .

macOS / Linux:

python3 -m venv venv
source venv/bin/activate
pip install -r requirements-training.txt
pip install -e .

πŸ› οΈ Existing Conda prefix cannot be activated

If venv contains conda-meta but the conda command is unavailable, it is a Conda prefix environment whose Conda installation is missing or not configured. You can still run the project directly with that environment's Python:

PowerShell:

& .\venv\python.exe .\app.py

Command Prompt:

venv\python.exe app.py

Git Bash:

./venv/python.exe app.py

To restore normal activation, install or repair Conda and then run:

conda activate .\venv
python app.py

πŸ§ͺ Option C β€” Conda with environment.yml

If you prefer a fully reproducible environment from a YAML file:

conda env create -f environment.yml
conda activate mlproject
pip install -e .

A ready-to-use environment.yml is provided β€” see below.


⚑ One-click helpers (optional)

  • Windows: double-click setup-windows.cmd
  • macOS / Linux: bash setup.sh

Both scripts create the env, install deps and print the next steps.


🧠 Train the model

# Training runs offline through the CLI, never through a public web endpoint.
pip install -r requirements-training.txt
python -m src.pipeline.train_pipeline

This produces:

artifacts/
β”œβ”€β”€ data.csv # raw ingested data
β”œβ”€β”€ train.csv # 80% split
β”œβ”€β”€ test.csv # 20% split
β”œβ”€β”€ preprocessor.pkl # ColumnTransformer
└── model.pkl # best model

▢️ Run the app

python app.py

Then open http://127.0.0.1:5000/ in your browser.


πŸ”Œ API

Method Route Description
GET / Colorful landing page
GET /predictdata Render the prediction form
POST /predictdata Predict the math score from form fields
GET /health JSON health-check incl. artifact existence

Example: POST /predictdata

curl -X POST http://127.0.0.1:5000/predictdata \
 -d "gender=female" \
 -d "race_ethnicity=group B" \
 -d "parental_level_of_education=bachelor's degree" \
 -d "lunch=standard" \
 -d "test_preparation_course=completed" \
 -d "reading_score=88" \
 -d "writing_score=92"

Returns the rendered HTML containing the predicted score.


πŸ—‚οΈ Project Structure

ML_Project/
β”œβ”€β”€ app.py # Flask entry-point + routes
β”œβ”€β”€ setup.py # Package configuration
β”œβ”€β”€ requirements.txt # Production/prediction server
β”œβ”€β”€ requirements-training.txt # Local training environment
β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
β”œβ”€β”€ .env.example
β”œβ”€β”€ artifacts/ # Generated at train-time
β”‚ β”œβ”€β”€ data.csv
β”‚ β”œβ”€β”€ train.csv / test.csv
β”‚ β”œβ”€β”€ preprocessor.pkl
β”‚ └── model.pkl
β”œβ”€β”€ logs/ # Timestamped log files
β”œβ”€β”€ notebook/
β”‚ β”œβ”€β”€ data/stud.csv
β”‚ β”œβ”€β”€ 1 . EDA STUDENT PERFORMANCE .ipynb
β”‚ └── 2. MODEL TRAINING.ipynb
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ components/
β”‚ β”‚ β”œβ”€β”€ data_ingestion.py
β”‚ β”‚ β”œβ”€β”€ data_transformation.py
β”‚ β”‚ └── model_trainer.py
β”‚ β”œβ”€β”€ pipeline/
β”‚ β”‚ β”œβ”€β”€ train_pipeline.py
β”‚ β”‚ └── predict_pipeline.py
β”‚ β”œβ”€β”€ utils.py
β”‚ β”œβ”€β”€ logger.py
β”‚ └── exception.py
β”œβ”€β”€ static/
β”‚ β”œβ”€β”€ css/style.css # Global styles
β”‚ └── js/main.js # UI polish (confetti, meter)
└── templates/
 β”œβ”€β”€ index.html # Landing page
 └── home.html # Prediction form

πŸ§ͺ Models Compared

Model Tuned?
Linear Regression βœ…
Decision Tree βœ…
Random Forest βœ…
Gradient Boosting βœ…
K-Neighbors Regressor βœ…
XGBRegressor βœ…
CatBoosting Regressor βœ…
AdaBoost Regressor βœ…

The best model (by R2 on the test set) is auto-selected and serialized to artifacts/model.pkl.


πŸ›‘οΈ Error Handling & Logging

  • All exceptions go through CustomException, which enriches messages with file name and line number.
  • Logs go to both logs/<timestamp>.log and the console.
  • Input validation protects against out-of-range scores and missing artifacts.

🧰 Tech Stack

Python Flask scikit-learn CatBoost XGBoost Pandas NumPy HTML5 CSS3 JavaScript


πŸ—ΊοΈ Roadmap

  • Colorful animated UI with confetti & score meter
  • Robust error handling & input validation
  • Configurable artifact paths (BASE_DIR-based)
  • /health API route
  • Dockerize the app
  • Add CI (GitHub Actions) β€” lint + import sanity
  • Add SHAP feature importance plot
  • Add unit tests with pytest

πŸ“Œ Project Notes

  • The app trains from data/stud.csv and writes generated artifacts to artifacts/.
  • Production/prediction server: pip install -r requirements.txt.
  • Local training environment: pip install -r requirements-training.txt.
  • Training must be run offline with python -m src.pipeline.train_pipeline, not through a public web endpoint. /health verifies that required artifacts are present.
  • The prediction UI is designed for local Flask runs and the bundled setup scripts help reproduce the same environment on Windows, macOS, and Linux.

🀝 Contributing

Contributions, issues and feature requests are welcome! Feel free to open an issue or PR.


πŸ“œ License

Distributed under the MIT License. See LICENSE for the full text.


Made with ❀️ by Asfi β€’ ⭐ this repo if you found it useful!

About

Machine learning web app that predicts student performance using Flask and scikit-learn, deployed on AWS Elastic Beanstalk

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /