Skip to content

vijaykushwaha-03/BigMart_dataset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

BigMart Sales Prediction - ML Deployment System

Crafted by Vijay Kumar Kushwaha

A production-ready machine learning system for predicting retail sales, featuring a REST API, modern web interface, comprehensive monitoring, and detailed documentation.

⚑ Features

  • πŸ€– ML-Powered Predictions: Gradient Boosting model with 60% RΒ² accuracy
  • πŸš€ FastAPI Backend: RESTful API with automatic documentation
  • πŸ’Ž Modern Web UI: Premium dark-mode interface with glassmorphism
  • πŸ“Š Real-time Analytics: Model performance metrics and API statistics
  • πŸ“ Comprehensive Logging: Structured JSON logs with rotation
  • πŸ“ˆ Prometheus Metrics: Production-ready monitoring
  • πŸ“¦ Batch Processing: Upload CSV for bulk predictions
  • βœ… Input Validation: Pydantic schemas ensure data quality

πŸ—οΈ Architecture

graph LR
    A[Web Frontend] -->|HTTP| B[FastAPI Server]
    B --> C[ML Service]
    C --> D[Trained Model]
    B --> E[Logger]
    B --> F[Metrics Collector]
    E --> G[Log Files]
    F --> H[Prometheus]
Loading

πŸš€ Quick Start

Prerequisites

  • Python 3.8+
  • 4GB RAM
  • Modern web browser

Installation

  1. Clone and Navigate
cd BigMart_dataset
  1. Create Virtual Environment
python3 -m venv venv
source venv/bin/activate  # Linux/Mac
# OR
venv\Scripts\activate  # Windows
  1. Install Dependencies
pip install -r requirements.txt
  1. Train the Model
python train_model.py

Expected output:

πŸ† Best Model: Gradient Boosting
   Test RΒ²: 0.6049
   RMSE: 1036.29
βœ… Model training completed!
  1. Start API Server
uvicorn api.main:app --reload --host 0.0.0.0 --port 8000
  1. Open Frontend
# In a new terminal
cd frontend
python3 -m http.server 8080

Then open: http://localhost:8080

πŸ“š Project Structure

BigMart_dataset/
β”œβ”€β”€ api/                      # FastAPI application
β”‚   β”œβ”€β”€ main.py              # App entry point
β”‚   β”œβ”€β”€ endpoints.py         # API routes
β”‚   β”œβ”€β”€ schemas.py           # Pydantic models
β”‚   β”œβ”€β”€ ml_service.py        # ML inference
β”‚   β”œβ”€β”€ logger.py            # Logging config
β”‚   └── monitoring.py        # Metrics collection
β”œβ”€β”€ frontend/                 # Web interface
β”‚   β”œβ”€β”€ index.html           # Main page
β”‚   β”œβ”€β”€ styles.css           # Premium CSS
β”‚   └── script.js            # API integration
β”œβ”€β”€ docs/                     # Documentation
β”‚   β”œβ”€β”€ MODEL_PIPELINE.md    # ML pipeline details
β”‚   β”œβ”€β”€ API_DOCUMENTATION.md # API reference
β”‚   β”œβ”€β”€ DEPLOYMENT_GUIDE.md  # Deployment instructions
β”‚   └── USER_GUIDE.md        # End-user guide
β”œβ”€β”€ logs/                     # Application logs
β”œβ”€β”€ train_model.py           # Model training script
β”œβ”€β”€ app.py                   # Streamlit app (legacy)
β”œβ”€β”€ bigmart.csv              # Training dataset
β”œβ”€β”€ requirements.txt         # Dependencies
└── README.md                # This file

🎯 Usage

Single Prediction

Via Web UI:

  1. Open http://localhost:8080
  2. Fill in product and outlet details
  3. Click "Predict Sales"

Via API (curl):

curl -X POST http://localhost:8000/api/v1/predict \
  -H "Content-Type: application/json" \
  -d '{
    "Item_Weight": 9.3,
    "Item_Visibility": 0.016,
    "Item_MRP": 249.81,
    "Outlet_Age": 26,
    "Item_Fat_Content": "Low Fat",
    "Item_Type": "Dairy",
    "Outlet_Size": "Medium",
    "Outlet_Location_Type": "Tier 2",
    "Outlet_Type": "Supermarket Type1"
  }'

Via Python:

import requests

response = requests.post(
    "http://localhost:8000/api/v1/predict",
    json={
        "Item_Weight": 9.3,
        "Item_Visibility": 0.016,
        "Item_MRP": 249.81,
        "Outlet_Age": 26,
        "Item_Fat_Content": "Low Fat",
        "Item_Type": "Dairy",
        "Outlet_Size": "Medium",
        "Outlet_Location_Type": "Tier 2",
        "Outlet_Type": "Supermarket Type1"
    }
)
print(response.json())

Batch Prediction

Upload a CSV file via the web UI or use the API:

import requests

with open('products.csv', 'rb') as f:
    response = requests.post(
        "http://localhost:8000/api/v1/batch-predict",
        files={'file': f}
    )
print(response.json())

πŸ“Š Model Performance

Metric Value Description
RΒ² Score 0.6049 Explains 60% of sales variance
RMSE β‚Ή1,036 Root mean squared error
MAE β‚Ή722 Mean absolute error
Model Gradient Boosting 100 estimators
Features 32 4 numerical + 28 categorical
Training Samples 6,818 80% of dataset

πŸ” API Endpoints

Endpoint Method Description
/api/v1/predict POST Single prediction
/api/v1/batch-predict POST Batch predictions
/api/v1/health GET Health check
/api/v1/model-info GET Model metadata
/api/v1/metrics GET Prometheus metrics
/api/v1/stats GET API statistics
/docs GET Swagger UI
/redoc GET ReDoc UI

πŸ“ Documentation

πŸ› οΈ Development

Running Tests

# Test API health
curl http://localhost:8000/api/v1/health

# View logs
tail -f logs/api.log
tail -f logs/predictions.log

# View metrics
curl http://localhost:8000/api/v1/metrics

Monitoring

Access real-time metrics:

🚒 Deployment

Docker

docker build -t bigmart-api .
docker run -p 8000:8000 bigmart-api

Systemd Service

sudo cp bigmart-api.service /etc/systemd/system/
sudo systemctl enable bigmart-api
sudo systemctl start bigmart-api

See Deployment Guide for detailed instructions.

🎨 Screenshots

Web Interface

  • Modern dark-mode design with glassmorphism
  • Responsive layout for mobile and desktop
  • Real-time prediction results with animations
  • Batch upload with drag-and-drop
  • Analytics dashboard with live metrics

API Documentation

  • Auto-generated Swagger UI at /docs
  • Interactive API testing
  • Complete request/response schemas

πŸ”§ Technology Stack

  • Backend: FastAPI, Uvicorn, Python 3.11
  • ML: scikit-learn, XGBoost, pandas, NumPy
  • Frontend: HTML5, CSS3 (Vanilla), JavaScript (ES6+)
  • Monitoring: Prometheus, structured JSON logging
  • Validation: Pydantic v2
  • Deployment: Docker, systemd, cloud-ready

πŸ“ˆ Future Enhancements

  • Add authentication (API keys, JWT)
  • Implement rate limiting
  • Add model retraining pipeline
  • Create mobile app
  • Add A/B testing for model versions
  • Implement caching (Redis)
  • Add more visualizations
  • Export predictions to Excel/PDF

🀝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

πŸ“„ License

This project is open source and available under the MIT License.

πŸ‘€ About the Author

Vijay Kumar Kushwaha

I am a passionate learner exploring AI, machine learning, and data science. This project demonstrates end-to-end ML deployment from data exploration to production-ready APIs. I'm always open to collaboration and feedback!


πŸ“ž Contact & Support

  • Issues: Open a GitHub issue
  • Documentation: See docs/ directory
  • Email: Contact through GitHub profile

⭐ If you found this project helpful, please consider starring the repository!

Last Updated: December 18, 2025
Version: 1.0.0

About

Perform EDA and model implementation and end to end model deployement

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors