End-to-end ML system for retail demand forecasting and inventory optimization
Combines XGBoost, Prophet, and Random Forest in an ensemble to achieve 87.5% forecast accuracy, quantifying $1M+ annual savings potential.
🎯 Live Demo: https://huggingface.co/spaces/maowi/sales-forecast-optimizer
- 🤖 ML Forecasting: Ensemble of XGBoost + Prophet + Random Forest
- 📦 Inventory Optimization: Safety stock, reorder points, EOQ calculations
- 💰 Financial Impact: Quantified savings with detailed breakdown
- 🧠 AI Insights: Groq LLM-powered natural language business analysis
- 📈 Interactive Dashboard: 5-page Streamlit dashboard with dark theme
- 🔌 REST API: FastAPI backend for programmatic access
| Metric | Value |
|---|---|
| Forecast Accuracy (MAPE) | 87.5% |
| Annual Savings | $1,003,750 |
| Working Capital Freed | $4,106,250 |
| Stores Analyzed | 54 stores |
| Training Data | 3M+ rows (Kaggle Store Sales) |
RetailFlow-AI/
├── src/
│ ├── data/ # ETL pipeline & data processing
│ ├── features/ # Feature engineering
│ ├── models/ # ML models (XGBoost, Prophet, RF)
│ ├── optimization/ # Inventory optimization algorithms
│ ├── insights/ # Groq LLM integration
│ ├── dashboard/ # Streamlit UI
│ └── api/ # FastAPI REST endpoints
├── data/
│ ├── raw/ # Original Kaggle data
│ └── output/ # Processed forecasts & metrics
├── notebooks/ # Jupyter notebooks (EDA, experiments)
└── tests/ # Unit tests
- Python 3.10+
- Git
- (Optional) Kaggle API credentials
git clone https://github.com/maowiz/RetailFlow-AI.git
cd RetailFlow-AI# Windows
python -m venv venv
.\venv\Scripts\activate
# macOS/Linux
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtCreate a .env file in the project root:
# Groq API (for AI insights)
GROQ_API_KEY=your_groq_api_key_here
# Data directory
DATA_DIR=data/output
# Kaggle credentials (optional, if downloading raw data)
KAGGLE_USERNAME=your_username
KAGGLE_KEY=your_api_keyGet free Groq API key: https://console.groq.com/keys
# Launch the dashboard with existing data
streamlit run src/dashboard/app.pyDashboard opens at http://localhost:8501
# 1. Download Kaggle data (requires Kaggle API setup)
python src/data/download_kaggle_data.py
# 2. Process data and train models
python src/models/train_all_models.py
# 3. Generate inventory recommendations
python src/optimization/run_optimization.py
# 4. Launch dashboard
streamlit run src/dashboard/app.py# Start API server
uvicorn src.api.main:app --host 0.0.0.0 --port 8000 --reloadAPI docs at http://localhost:8000/docs
Example API Call:
import requests
# Get forecast for stores 1-5
response = requests.post('http://localhost:8000/predict', json={
"store_ids": [1, 2, 3, 4, 5],
"horizon_days": 14,
"model": "ensemble"
})
forecast = response.json()
print(f"Total forecasted sales: ${forecast['total_forecasted_sales']:,.0f}")-
Executive Overview
KPIs, risk summary, time series charts, priority recommendations -
Sales Forecasts
Interactive time series, store heatmaps, model comparison, filters -
Inventory Optimization
Safety stock levels, inventory turnover, reorder points, risk gauges -
Financial Impact
Savings waterfall, cost breakdown, ROI analysis -
AI Insights
Groq-powered Q&A, forecast analysis, weekly reports
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | System information |
/health |
GET | Health check with data stats |
/predict |
POST | Generate sales forecasts |
/optimize-inventory |
POST | Get inventory recommendations |
/insights |
POST | AI-powered business insights |
Full API docs: http://localhost:8000/docs (when server is running)
# Run API tests
python test_api.py
# Run Phase 6 Groq tests
python test_phase6.py
# Unit tests (if available)
pytest tests/- Source: Kaggle Store Sales dataset (125K stores × 33 products × daily)
- Processing: Missing value imputation, outlier detection, date feature extraction
- Features: 50+ engineered features (lags, rolling stats, holidays, promotions)
- XGBoost: Gradient boosting for non-linear patterns
- Prophet: Handles seasonality and holidays
- Random Forest: Ensemble robustness
- Ensemble: Weighted average (40% XGB, 30% Prophet, 30% RF)
- Safety Stock:
z × σ_lead × √lead_time - Reorder Point:
avg_demand × lead_time + safety_stock - EOQ:
√(2 × D × S / H) - Risk Scoring: Composite of demand variability, forecast error, stockout history
- Holding Cost Reduction: Optimized inventory levels
- Stockout Cost Avoidance: Improved service levels
- Working Capital Gains: Reduced excess inventory
Contributions welcome! Please see CONTRIBUTING.md for guidelines.
Ideas for contributions:
- Add more ML models (LSTM, Transformer, etc.)
- Implement A/B testing framework
- Add unit tests
- Improve dashboard UX
- Add deployment guides (AWS, Azure, GCP)
This project is licensed under the MIT License — see LICENSE file for details.
- Dataset: Kaggle Store Sales Competition
- Groq: Free LLM API for AI insights
- Hugging Face: Free hosting for demo dashboard
Author: Maowi
GitHub: @maowiz
Live Demo: HuggingFace Space
If you find this project helpful, please give it a ⭐ — it helps others discover it too!
- Installation Guide (detailed setup)
- API Documentation (endpoint reference)
- Architecture (system design)
- Deployment Guide (production setup)
Built with ❤️ for the open-source community