Sales and demand forecasting for supply chain optimization using machine learning and deep learning. Compare Linear Regression, XGBoost, CNN, LSTM, CNN-LSTM, GRU, and Transformer models for inventory and replenishment optimization.
| Author | KuchikiRenji |
| KuchikiRenji@outlook.com | |
| GitHub | github.com/KuchikiRenji |
| Discord | kuchiki_renji |
This repository implements supply chain demand forecasting and sales forecasting using both machine learning and deep learning models. The goal is to predict future sales to support:
- Inventory optimization — match store inventory to demand and reduce storage/rental costs
- Replenishment optimization — optimize order quantities to minimize warehouse-to-store replenishments and cut warehousing and transportation costs
- Business model design — identify factors that drive sales for strategy and optimization
The project uses store–item daily sales data (date, store, item, sales) with rich time-based and aggregate features, and compares multiple ML/DL architectures for accuracy and practicality.
- Sales trend understanding — Forecast future sales from historical patterns.
- Inventory optimization — Align store inventory with actual demand to reduce storage space and rental cost.
- Replenishment optimization — Optimize replenishment quantity per order to minimize the number of replenishments between warehouse and stores (reducing warehousing and transportation costs).
- Factor analysis — Find factors that affect sales to design and optimize the business model.
| Model | Description |
|---|---|
| Linear Regression | Best-fit linear relationship between dependent and independent variables. |
| XGBoost | Gradient boosted decision trees with regularization and parallel split selection. |
| Model | Description |
|---|---|
| CNN | Feedforward network effective for time series forecasting. |
| LSTM | Recurrent network that addresses standard RNN limitations. |
| CNN-LSTM | CNN for feature extraction from time series, LSTM for sequence prediction. |
| GRU | Gated recurrent unit with fewer parameters, designed to mitigate vanishing gradients. |
| Transformer | Self-attention over input sequence, weighting importance of each time step. |
Supply-Chain-forecasting-deep-learning/
├── README.md
├── Transformer.py # Transformer model (Keras/TensorFlow)
├── Sales Demand Forecast.ipynb # Main notebook: ML + DL comparison
├── Sales Demand Forecast- Transformer model.ipynb # Transformer pipeline
├── CNN_MODEL.h5
├── CNN-LSTM_MODEL.h5
├── GRU_MODEL.h5
└── LSTM_MODEL.h5
- Notebooks: Data loading, feature engineering, training, and evaluation for all models.
- Transformer.py: Reusable Transformer architecture with configurable look-back, horizon, and attention.
- Pre-trained models: Saved Keras models (
.h5) for CNN, CNN-LSTM, GRU, and LSTM.
- Python 3.7+
- Libraries:
tensorflow(orkeras),scikit-learn,pandas,numpy,xgboost,matplotlib,seaborn,plotly
Install core dependencies:
pip install tensorflow scikit-learn pandas numpy xgboost matplotlib seaborn plotlyFor the Transformer notebook, ensure parameters.json and utils (e.g. utils.py with rmse, smape, coeff_determination, series_to_supervised) are available in the project root.
The notebooks expect a train dataset with columns: date, store, item, sales. Update the CSV path in the notebook to your own file (e.g. replace the path to train.csv with your dataset location).
- Open
Sales Demand Forecast.ipynbfor the full ML/DL comparison (Linear Regression, XGBoost, CNN, LSTM, CNN-LSTM, GRU). - Open
Sales Demand Forecast- Transformer model.ipynbfor the Transformer-based forecasting pipeline.
- Best performers in this project: XGBoost (ML) and CNN-LSTM (DL).
- XGBoost: Good forecasts with minimal hyperparameter tuning, works with fewer data/features, includes regularization to limit overfitting and supports fast parallel training.
- CNN-LSTM: Convolution layers extract features from time series, pooling retains important information, and the LSTM layer models temporal dependencies for accurate next-step prediction.
This project is open source. For usage and licensing terms, see the repository license or contact the author.
Keywords: supply chain forecasting, demand forecasting, sales forecasting, deep learning, LSTM, CNN, Transformer, XGBoost, time series, inventory optimization, replenishment optimization, TensorFlow, Keras.