Python Xgboost scikit-learn Streamlit demand-forecasting supply-chain Machine Learning
A machine learning-based retail sales forecasting system that predicts daily store sales using historical sales data, store characteristics, promotions, holidays, competition information, and time-based features.
Demand-forcasting-demo.mp4
🌐 Streamlit App: https://dynamic-demand-forecasting.streamlit.app/
Accurate demand forecasting helps retailers make better decisions about inventory, staffing, and promotional planning.
This project develops a Retail Sales Forecasting system using Machine Learning to predict daily sales for retail stores.
The project covers the complete Machine Learning workflow:
Data Collection → Data Preprocessing → EDA → Feature Engineering → Model Training → Model Evaluation → Deployment
The main objectives of this project are to:
- Predict daily retail store sales.
- Identify important factors affecting sales.
- Compare different regression algorithms.
- Select the best-performing model based on evaluation metrics.
- Deploy the final model as an interactive Streamlit application.
- Support better demand and inventory planning.
- Dataset: Rossmann Store Sales
- Source: Kaggle
- Final Dataset Size: 844,338 rows
- Features: 18
- Target Variable:
Sales
The dataset contains information related to:
- Store characteristics
- Promotions
- Holidays
- Competition
- Product assortment
- Historical sales
- Date and seasonal patterns
- Python
- Pandas
- NumPy
- Scikit-learn
- XGBoost
- Matplotlib
- Seaborn
- Joblib
- Streamlit
- Merged
sales.csvandstore.csvusing theStorecolumn. - Handled missing values.
- Removed the
Customersfeature to avoid data leakage during forecasting. - Filtered records where stores were open and sales were greater than zero.
- Converted the
Datecolumn into a datetime format.
Created additional time-based features:
YearMonthDayWeekOfYearIsWeekend
Categorical variables were processed using:
ColumnTransformer + OneHotEncoder
This converts categorical features such as StoreType, Assortment, and PromoInterval into numerical features suitable for Machine Learning models.
Several analyses were performed to understand sales patterns:
- Sales distribution
- Average monthly sales
- Average sales by day of week
- Sales during promotional and non-promotional periods
- Sales distribution across store types
- Numerical feature correlation analysis
- XGBoost feature importance
- Sales show noticeable variation across different months.
- Promotional periods are associated with higher average sales.
- Sales patterns vary across different store types.
- Store type and promotion-related features were among the important predictors in the final XGBoost model.
Four regression algorithms were trained and evaluated:
- Linear Regression
- Decision Tree Regressor
- Random Forest Regressor
- XGBoost Regressor
The models were evaluated using:
- MAE — Mean Absolute Error
- MSE — Mean Squared Error
- RMSE — Root Mean Squared Error
- R² Score
| Metric | XGBoost |
|---|---|
| MAE | 757.67 |
| RMSE | 1066.65 |
| R² Score | 0.8821 |
The XGBoost Regressor achieved the best overall performance among the models evaluated and was selected as the final model.
The model explains approximately 88.21% of the variation in sales on the test data.
Feature importance analysis was performed using the trained XGBoost model.
Some of the important features included:
StoreType_bPromoPromo2SinceYearCompetitionDistancePromoIntervalPromo2CompetitionOpenSinceYearCompetitionOpenSinceMonthAssortmentStore
This helps provide insight into the factors influencing the model's sales predictions.
The trained XGBoost model was deployed using Streamlit.
The application allows users to provide store-related inputs and receive an estimated daily sales prediction.
User Input → Preprocessing → Trained XGBoost Model → Sales Prediction
The trained model is saved using Joblib and loaded by the Streamlit application during prediction.
Dynamic-Supply-Chain-Demand-Forecasting/
│
├── app.py
├── README.md
├── LICENSE
├── requirements.txt
├── .gitignore
│
├── data/
│ ├── sales.csv
│ └── store.csv
│
├── models/
│ └── xgboost_sales_model.pkl
│
├── notebooks/
└── Retail_Sales_Forecasting.ipynb
The forecasting system can support:
- 📦 Inventory planning
- 🏪 Store-level demand planning
- 👥 Staff allocation
- 📢 Promotional planning
- 📊 Sales analysis
- 🚚 Supply chain decision-making
Accurate demand predictions can help businesses reduce the risk of overstocking and understocking and make more informed operational decisions.
Muhammed Fayis
Data Science Machine Learning