An end-to-end production-style machine learning system for forecasting retail demand using dynamic feature engineering, asynchronous external data integration, and real-time inference.
This project goes beyond a typical ML model by implementing a complete ML system pipeline, including:
- Historical demand modeling
- Automated lag feature generation
- External data integration (weather)
- Feature engineering pipeline
- REST API for real-time predictions
- Cloud deployment (on Render)
Forecast weekly sales for retail stores based on:
- Historical sales trends
- Store characteristics
- Promotions
- Economic indicators
- Weather conditions
- Dynamically retrieves past sales from a feature store (
history.csv) - Eliminates need for manual lag inputs
- Ensures training-serving consistency
- Fetches real-time weather data using OpenWeather API
- Uses
asynccalls for non-blocking execution - Supports multiple store locations
- Prevents redundant API calls
- Improves latency and efficiency
- Time-based features (year, month, week, day)
- Store size categorization
- Promotion aggregation (
total_markdown) - Rolling statistics & lag features
- Model: XGBoost Regressor
- Optimized using:
- Depth tuning
- Learning rate adjustment
- Feature selection
- Target transformation using
log1p
- Built using FastAPI
- Accepts structured JSON input
- Returns predicted weekly sales
- Deployed on Render
- Publicly accessible API endpoint
Request → API (FastAPI) → Lag Feature Retrieval (history.csv) → Weather Fetch (Async API) → Feature Engineering → Model Prediction (XGBoost) → Response
git clone https://github.com/shubhro2002/demand-intelligence-system.git
cd demand-intelligence-system
python -m venv venv
venv\Scripts\activate # Windows
pip install -r requirements.txtCreate a .env file (for local use):
API_KEY=your_openweather_api_keyuvicorn src.api.main:app --reloadOpen Swagger UI:
http://127.0.0.1:8000/docs{
"Store": 1,
"Dept": 1,
"IsHoliday": 0,
"Size": 150000,
"Type": "A",
"CPI": 220,
"Unemployment": 7.5,
"Fuel_Price": 3.5,
"MarkDown1": 0,
"MarkDown2": 0,
"MarkDown3": 0,
"MarkDown4": 0,
"MarkDown5": 0,
"Date": "2012-11-23"
}{
"predicted_weekly_sales": 8113.30
}The application is deployed on Render:
https://demand-intelligence-system.onrender.com/
Interactive API Docs:
https://demand-intelligence-system.onrender.com/docs
| Metric | Value |
|---|---|
| MAE | ~2457 |
| RMSE | ~5016 |
- Designing stateful ML systems using feature stores
- Handling training-serving skew
- Implementing async pipelines in APIs
- Managing external dependencies with caching
- Deploying ML systems on cloud platforms
- Replace CSV with real feature store (e.g., Feast)
- Add real macroeconomic data APIs
- Implement model monitoring
- Dockerize for scalable deployment
- Python
- FastAPI
- XGBoost
- Pandas / NumPy
- AsyncIO / aiohttp
- Render (Deployment)
Feel free to fork and improve the project!
Give it a star⭐!