Predicting future retail sales using historical data and XGBoost Regression.
Sales forecasting plays a crucial role in retail businesses by helping estimate future demand. Accurate predictions enable businesses to optimize inventory, reduce stock shortages, improve promotional planning, and make informed operational decisions.
This project develops a Sales Demand Forecasting model using historical retail sales data and the XGBoost Regressor. The workflow includes data preprocessing, exploratory data analysis (EDA), feature engineering, model training, evaluation, and forecasting.
- Analyze historical sales trends
- Perform data preprocessing and feature engineering
- Build a machine learning forecasting model
- Predict future sales
- Evaluate model performance
- Generate business insights for decision-making
The project uses the Store Sales Forecasting Dataset containing historical sales records.
| Feature | Description |
|---|---|
| id | Record ID |
| date | Date of transaction |
| store_nbr | Store number |
| family | Product category |
| sales | Sales value (Target Variable) |
| onpromotion | Number of promoted products |
- Python
- Pandas
- NumPy
- Matplotlib
- Scikit-Learn
- XGBoost
- Jupyter Notebook
FUTURE_ML_01
│
├── data/
│ └── train.csv
│
├── images/
│ ├── sales_trend.png
│ ├── feature_importance.png
│ ├── forecast_2017.png
│ └── actual_vs_predicted.png
│
├── models/
│
├── notebooks/
│ └── Sales_Demand_Forecasting.ipynb
│
├── .gitignore
└── README.md
- Loaded historical retail sales dataset
- Checked data structure
- Verified missing values
- Inspected feature types
Performed analysis including:
- Sales trend over time
- Product family analysis
- Distribution of sales
- Business observations
Created time-based features including:
- Year
- Month
- Day
- Day of Week
- Quarter
- Week of Year
These features help the model capture seasonal demand patterns.
Since this is a forecasting problem, a time-based split was used.
Training Data:
- 2013–2016
Testing Data:
- 2017
This prevents future information from leaking into training.
Model Used:
XGBoost Regressor
Reasons for choosing XGBoost:
- Handles nonlinear relationships
- High prediction accuracy
- Efficient for structured/tabular datasets
- Excellent performance for regression problems
| Metric | Score |
|---|---|
| MAE | 137.04 |
| RMSE | 401.45 |
| R² Score | 0.9122 |
The model explains over 91% of the variation in sales, indicating strong predictive performance.
The analysis revealed several key findings:
- Product category is the most influential factor affecting sales.
- Promotional campaigns significantly increase demand.
- Sales vary considerably across stores.
- Seasonal and calendar-based patterns influence purchasing behavior.
- Historical trends provide strong predictive power for future demand.
This forecasting system can help businesses:
- Improve inventory management
- Reduce stock shortages
- Minimize excess inventory
- Optimize promotional campaigns
- Improve staffing decisions
- Support budgeting and financial planning
Possible enhancements include:
- Hyperparameter tuning using GridSearchCV
- Cross-validation with TimeSeriesSplit
- Incorporating holiday and weather data
- Deploying the model using Streamlit
- Real-time sales prediction dashboard
- Deep Learning models (LSTM)
✔ Data preprocessing completed
✔ Exploratory Data Analysis performed
✔ Feature engineering implemented
✔ XGBoost forecasting model developed
✔ Model evaluated successfully
✔ Business insights generated
✔ Future sales forecast visualized
Saksham Verma
GitHub: https://github.com/saktronX
LinkedIn: (Add your LinkedIn profile link here)
This project was completed as part of the Future Interns Machine Learning Internship (Task 1 – Sales Demand Forecasting).



