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.
- π€ 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
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]
- Python 3.8+
- 4GB RAM
- Modern web browser
- Clone and Navigate
cd BigMart_dataset- Create Virtual Environment
python3 -m venv venv
source venv/bin/activate # Linux/Mac
# OR
venv\Scripts\activate # Windows- Install Dependencies
pip install -r requirements.txt- Train the Model
python train_model.pyExpected output:
π Best Model: Gradient Boosting
Test RΒ²: 0.6049
RMSE: 1036.29
β
Model training completed!
- Start API Server
uvicorn api.main:app --reload --host 0.0.0.0 --port 8000- Open Frontend
# In a new terminal
cd frontend
python3 -m http.server 8080Then open: http://localhost:8080
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
Via Web UI:
- Open http://localhost:8080
- Fill in product and outlet details
- 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())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())| 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 |
| 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 |
- Model Pipeline: Data preprocessing, feature engineering, model training
- API Documentation: Complete API reference with examples
- Deployment Guide: Local and production deployment
- User Guide: Step-by-step user instructions
# 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/metricsAccess real-time metrics:
- API Stats: http://localhost:8000/api/v1/stats
- Prometheus: http://localhost:8000/api/v1/metrics
- Logs:
logs/directory
docker build -t bigmart-api .
docker run -p 8000:8000 bigmart-apisudo cp bigmart-api.service /etc/systemd/system/
sudo systemctl enable bigmart-api
sudo systemctl start bigmart-apiSee Deployment Guide for detailed instructions.
- 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
- Auto-generated Swagger UI at
/docs - Interactive API testing
- Complete request/response schemas
- 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
- 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
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is open source and available under the MIT License.
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!
- 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