Forecasting at scale: demand prediction with Random Forests and neural nets
๐ฏ Why this post exists
Inventory decisions are where strategy meets survival. Demand forecasting isn’t just a data science problemโit’s the heartbeat of retail, logistics, and supply chain optimization.
This post tells the story of how we built a modular, scalable Demand Forecasting Platform that uses Random Forest, Artificial Neural Networks, and Hybrid Time Series modelsโall running on top of a robust Data Lake infrastructure powered by Apache Hadoop and Spark.
๐ Real-World Chaos: The problem statement
Forecasting demand for every SKU across regions, seasons, and supply timelines is a nightmare. Every error costs time, money, and customer trust.
We tackled this by building models to answer:
- Will this product sell next month?
- How much should we stock?
- Will this item become obsolete?
๐งฑ System architecture at a glance
graph TD
A[Raw Data] --> B[HDFS Storage]
B --> C[Preprocessing on Spark]
C --> D[Model Training]
D --> E[Forecasting Output]
E --> F[Dashboards, Alerts]
๐งน Phase 1: Raw data to gold
๐ฅ Data Ingestion
We collected:
- Historical sales (3 years)
- Stock movement logs
- Product metadata
- Customer classification
- Seasonal promotion flags
๐งช Exploratory Data Analysis (EDA)
Sanity checks and patterns:
| |
We applied:
- Pearson/Spearman correlation checks
- Distribution analysis
- Outlier treatment (IQR-based)
- Stationarity tests (ADF)
๐ง Phase 2: Forecasting strategy
We didnโt pick just one model. We created an ensemble strategy combining:
- Statistical models (ETS, ARIMA, Holt-Winters)
- Machine Learning (Random Forest)
- Deep Learning (Artificial Neural Networks)
Each approach had its domain:
- Time series models โ seasonal & trend patterns
- ML classifiers โ product obsolescence
- ANNs โ nonlinear patterns and demand spikes
๐ Hybrid forecasting logic
| |
The model pipeline:
- Lag features (7, 14, 28 days)
- Sliding windows
- Forecast horizon: 30 days
- Evaluation: MAPE, RMSE
๐งฌ Data Engineering backbone
| |
All models ran in batch mode orchestrated by Oozie, and outputs were stored in Hive for dashboards.
๐งช Random Forest for obsolescence
| |
Key Features:
- Time since last sale
- Category demand index
- Stockout frequency
- Geographic demand
๐ค ANN for demand prediction
| |
Tuned using:
- ReLU activation
- Adam optimizer
- 30 epochs
๐งช Time series models
ETS and ARIMA used via statsmodels.
| |
๐ Use Case: Product B - Engine Oil Additive
Scenario:
- 18-month sales history
- Sudden spikes near monsoon
- Southern region dominates demand
Model predicted:
| Month | Forecasted Demand | Model Used | Confidence |
|---|---|---|---|
| Aug 2025 | 142 | Hybrid (RF+ANN) | ยฑ4% |
| Sep 2025 | 110 | Hybrid (RF+ANN) | ยฑ5% |
๐ Dashboard Integration
All output forecasts were published into:
- Tableau for visual insight
- Superset for stakeholder self-serve access
Forecast deviation alerts were published via email & SMS using custom logic.
๐ Modular design
Every step in the pipeline was modular:
- Ingestion node
- Preprocessing node
- Forecasting node
- Alerting node
Can be independently replaced or improved.
graph LR
Ingestion[Ingestion Node] --> Preprocessing[Preprocessing Node]
Preprocessing --> Forecasting[Forecasting Node]
Forecasting --> Alerting[Alerting Node]
๐งฎ Evaluation metrics
| Model | RMSE | MAPE | Obsolescence Accuracy |
|---|---|---|---|
| ARIMA | 22.3 | 14.2% | - |
| ANN | 18.9 | 11.5% | - |
| Hybrid (RF+ANN) | 16.2 | 9.1% | 96.3% |
๐ Appendix: Sample forecast output (JSON)
| |
๐ง Technical learnings
- Feature engineering matters more than model choice
- Combining time-series and ML gives best of both worlds
- Spark + Hadoop made scaling data preprocessing easy
- Modular pipeline = easier model updates + CI/CD
๐ผ Business wins
- 28% drop in overstock
- 35% better accuracy than old Excel-based systems
- Zero stockouts during peak sales week
- Data science + supply chain teams now speak the same language
๐ก Final thoughts
You donโt need a PhD to build world-class forecasting.
You need:
- Clean data
- Smart features
- Modular design
- Monitoring & alerting
And maybe, a sarcastic blog post to explain it.
๐ ๏ธ Future plans
- Integrate Facebook Prophet & DeepAR
- GPU training for ANN
- Dockerized microservices for forecasts
- Push-button retraining with Airflow
๐ Feedback?
Email: [email protected]

Image placeholder: from raw data to predictions
