Predicting future retail sales using Machine Learning techniques, store information, promotional campaigns, competition data, and temporal patterns.
Accurate sales forecasting is one of the most important challenges in retail. Reliable forecasts help companies optimize inventory levels, improve promotional planning, allocate resources efficiently, and support strategic business decisions.
This project applies supervised Machine Learning techniques to forecast future sales for Rossmann stores using historical sales records, store characteristics, promotional activities, competition information, and temporal features.
Two regression models were developed and compared: Random Forest Regressor and XGBoost Regressor. The final model was selected based on predictive performance using MAE, RMSE, and R² metrics.
Retail businesses must continuously estimate future demand to avoid stock shortages, reduce excess inventory, and improve operational efficiency.
The objective of this project is to build predictive models capable of estimating future store sales based on historical business data and store-related operational factors.
Reliable forecasts can support:
- Inventory Planning
- Demand Forecasting
- Promotional Strategy Optimization
- Workforce Allocation
- Revenue Planning
- Data-Driven Decision Making
The dataset contains:
- Historical daily sales records
- Store information
- Promotional campaign details
- Competition information
- Holiday indicators
- Assortment information
- 1,017,209 sales records
- 1,115 stores
- 41,088 unseen observations for future forecasting
Dataset Source:
https://www.kaggle.com/competitions/rossmann-store-sales/data
- Python
- Pandas
- NumPy
- Matplotlib
- Seaborn
- Scikit-Learn
- Random Forest Regressor
- XGBoost Regressor
- Jupyter Notebook
- Data Loading
- Dataset Integration
- Initial Data Exploration
- Missing Values and Statistical Summary
- Data Cleaning
- Time-Based Feature Engineering
- Exploratory Data Analysis
- Data Preprocessing
- Temporal Train-Test Split
- Random Forest Sales Forecasting
- XGBoost Sales Forecasting
- Model Evaluation
- Actual vs Predicted Sales Analysis
- Feature Importance Analysis
- Model Performance Comparison
- Future Sales Forecasting
- Sales Forecast for Unseen Data
- Project Conclusion
Before model development, the dataset was inspected for missing values and descriptive statistics.
Missing information related to competition and promotion variables was identified and treated using appropriate imputation strategies. Statistical summaries were also analyzed to better understand sales variability, store behavior, and feature distributions.
This step ensured data quality and prepared the dataset for subsequent exploratory analysis and modeling.
To improve forecasting performance, new temporal variables were created from the original date column.
Generated features included:
- Year
- Month
- Day
- Week
- DayOfWeek
- IsWeekend
These variables help the model capture recurring sales patterns, seasonality effects, and temporal business behavior.
Exploratory analysis was performed to understand sales behavior, identify seasonal patterns, evaluate promotional impacts, and investigate store characteristics.
The analysis revealed important business insights regarding seasonality, store formats, competition effects, and promotional performance, which later influenced the forecasting models.
The sales distribution presents a positively skewed pattern, where most observations are concentrated between moderate sales values while a smaller number of stores achieve significantly higher sales volumes.
This behavior is common in retail environments and highlights the presence of high-performing stores that can strongly influence total revenue. The long right tail indicates that forecasting models must be capable of handling substantial variability and nonlinear sales patterns.
The monthly sales trend reveals recurring fluctuations throughout the analyzed period.
Several pronounced peaks and declines can be observed, suggesting the presence of seasonality, promotional cycles, holiday effects, and changing market conditions. Notably, sales increased considerably during specific periods while showing temporary declines in late 2014.
Capturing these temporal dynamics is essential for building reliable forecasting models capable of adapting to changing business conditions.
Analyzing average sales by month reveals a clear seasonal pattern across the retail calendar.
December achieved the highest average sales levels, significantly outperforming the other months. This behavior is likely associated with holiday shopping periods and increased consumer spending.
Months such as August, September, and October showed comparatively lower average sales levels, indicating periods of reduced demand.
Understanding these seasonal patterns is crucial for inventory planning, workforce allocation, and promotional scheduling.
Store performance varies considerably across different store formats.
Store Type B achieved average sales above 10,000 units, substantially outperforming Types A, C, and D, which remained close to the 7,000-unit range.
This result suggests that store format, location characteristics, customer demographics, or operational strategies have a significant impact on sales performance.
The strong differences between store types also help explain why store-related variables became important predictors in the forecasting model.
Promotions had a substantial impact on store performance.
Stores running promotional campaigns achieved average sales of approximately 8,200 units, while stores without promotions averaged around 5,900 units.
This represents an increase of nearly 39%, highlighting promotional campaigns as one of the strongest revenue drivers identified in the analysis.
For retail managers, this finding reinforces the importance of strategic campaign planning and targeted promotional initiatives to maximize sales performance.
Two Machine Learning regression models were developed and evaluated.
| Model | MAE | RMSE | R² Score |
|---|---|---|---|
| Random Forest | 736.36 | 1078.64 | 0.8798 |
| XGBoost | 1113.61 | 1490.09 | 0.7706 |
The Random Forest model achieved the best predictive performance, producing lower forecasting errors and a significantly higher R² score.
This indicates that Random Forest was more effective at capturing nonlinear relationships between sales, promotions, store characteristics, competition factors, and temporal patterns.
Random Forest outperformed XGBoost across all evaluation metrics, achieving substantially lower forecasting errors and stronger explanatory power.
The model was particularly effective at capturing nonlinear relationships between promotional activities, competition factors, store-specific characteristics, and temporal patterns.
Its lower MAE and RMSE values indicate more accurate sales estimates, while the higher R² score demonstrates a stronger ability to explain sales variability across different stores and time periods.
As a result, Random Forest was selected as the final forecasting model.
The scatter plot compares actual sales values against model predictions.
Most observations are concentrated near the diagonal reference line, indicating that predicted values closely follow real sales behavior across a wide range of sales levels.
Some dispersion can be observed for very high sales volumes, which is expected in retail forecasting due to promotional spikes and unusual demand events.
Overall, the strong concentration around the ideal prediction line demonstrates that the Random Forest model captured the underlying sales patterns and generalized well to unseen observations.
Feature importance analysis revealed the variables that contributed most to forecasting performance.
- Competition Distance
- Store ID
- Promotional Campaigns (Promo)
- Competition Opening Month
- Competition Opening Year
Competition Distance emerged as the most influential feature, suggesting that local competitive pressure plays a major role in store performance.
Stores located closer to competitors may experience stronger competitive pressure, directly affecting customer demand and sales behavior.
Store-specific characteristics also proved highly relevant, indicating that individual stores exhibit unique sales patterns that strongly affect forecasting accuracy.
Promotional activities ranked among the top predictors, reinforcing previous findings that marketing campaigns have a substantial impact on revenue generation.
The forecast comparison demonstrates that the Random Forest model captured both the overall sales level and short-term fluctuations throughout the evaluation period.
Predicted values closely followed actual sales behavior, including recurring peaks and declines observed across multiple weeks.
Although minor deviations occur during extreme sales events, the model consistently reproduces the underlying demand pattern, making it suitable for operational forecasting and business planning applications.
After model validation, the final Random Forest model was applied to the Rossmann test dataset containing 41,088 previously unseen observations.
The resulting forecasts were exported as:
sales_forecast_predictions.csv
| Metric | Value |
|---|---|
| Total Forecasts | 41,088 |
| Average Predicted Sales | 6,902 |
| Median Predicted Sales | 6,410 |
| Standard Deviation | 2,787 |
| Minimum Predicted Sales | 973 |
| Maximum Predicted Sales | 31,205 |
The prediction distribution indicates substantial variability across stores and time periods.
Most forecasts were concentrated between approximately 5,000 and 8,200 sales units, while a smaller number of observations reached significantly higher values above 30,000 units.
These results are consistent with the historical sales distribution observed during exploratory analysis and suggest that the model is capable of generating realistic forecasts across both average-performing and high-performing stores.
- Promotional campaigns increased average sales by approximately 39%.
- Competition distance was the most influential factor affecting store performance.
- Store-specific characteristics significantly contributed to sales variability.
- Strong seasonal patterns were observed throughout the dataset.
- December consistently generated the highest average sales volumes.
- Different store formats exhibited significantly different sales behaviors.
- Machine Learning models can effectively support retail demand forecasting and operational planning.
Although the results are promising, some limitations should be considered:
- External variables such as weather conditions and local events were not included.
- Economic factors and inflation effects were not available in the dataset.
- XGBoost was implemented without extensive hyperparameter optimization.
- Forecasting performance may decrease during unusual market conditions.
- A single temporal train-test split was used instead of rolling validation windows.
Potential enhancements for future versions include:
- Hyperparameter optimization using GridSearchCV or Optuna.
- Time-series cross-validation with rolling windows.
- Evaluation of LightGBM, CatBoost, Prophet, and SARIMA models.
- Integration of weather and economic indicators.
- Development of an interactive forecasting dashboard.
- Deployment as a real-time forecasting API.
This project developed a complete sales forecasting pipeline using Machine Learning techniques.
Among the evaluated models, Random Forest achieved the best performance, reaching an R² Score of 0.88 while significantly outperforming XGBoost.
The analysis demonstrated that competition intensity, store characteristics, promotional activities, and seasonal patterns are key drivers of retail sales performance.
The resulting forecasting system can support inventory planning, promotional strategy optimization, resource allocation, and data-driven business decisions, demonstrating the practical value of Machine Learning in retail operations.
Sales-Forecasting/
│
├── data/
│ ├── train.csv
│ ├── store.csv
│ ├── test.csv
│ └── sales_forecast_predictions.csv
│
├── images/
│ ├── sales_distribution.png
│ ├── monthly_sales_trend.png
│ ├── average_sales_by_month.png
│ ├── store_type_sales.png
│ ├── promotion_impact.png
│ ├── actual_vs_predicted_sales.png
│ ├── feature_importance.png
│ └── future_sales_forecast.png
│
├── notebooks/
│ └── sales_forecasting.ipynb
│
├── README.md
├── requirements.txt
└── .gitignoreTalita Niqian Lin Wu
LinkedIn: https://www.linkedin.com/in/talita-niqian-lin-wu/
This project applies supervised Machine Learning techniques to forecast future sales for Rossmann stores using historical sales data, store characteristics, promotional activities, competition information, and temporal patterns.
The objective is to develop predictive models capable of estimating future sales and uncovering the key factors that influence store performance. The resulting forecasts can support inventory planning, promotional strategy optimization, demand forecasting, and data-driven business decisions.
- Analyze historical sales behavior
- Identify seasonal and promotional sales patterns
- Engineer time-based features for forecasting
- Develop Machine Learning forecasting models
- Compare model performance
- Generate future sales predictions
- Extract business insights from sales data
Rossmann Store Sales Dataset
The dataset contains:
- Historical daily sales records
- Store information
- Promotional campaign details
- Competition information
- Holiday indicators
- Assortment information
Dataset source:
https://www.kaggle.com/competitions/rossmann-store-sales/data
- Python
- Pandas
- NumPy
- Matplotlib
- Seaborn
- Scikit-learn
- Random Forest Regressor
- XGBoost Regressor
- Jupyter Notebook
- Data Loading
- Dataset Integration
- Data Understanding
- Exploratory Data Analysis (EDA)
- Data Cleaning
- Missing Values Treatment
- Feature Engineering
- Time-Based Feature Creation
- Data Preprocessing
- Temporal Train-Test Split
- Random Forest Modeling
- XGBoost Modeling
- Model Evaluation
- Forecast Analysis
- Feature Importance Analysis
- Future Sales Forecasting
- Business Insights and Conclusions
The sales distribution shows a positively skewed pattern, where most stores generate moderate sales volumes while a smaller number of observations reach significantly higher sales values.
This behavior is common in retail datasets and highlights the importance of using robust Machine Learning models capable of handling nonlinear relationships.
Monthly sales analysis reveals fluctuations over time, indicating the presence of seasonality and changing business conditions throughout the observation period.
Understanding these patterns is essential for building reliable forecasting models.
Promotional campaigns have a strong positive effect on sales performance.
Stores running promotions achieved substantially higher average sales compared to periods without promotions, confirming that marketing actions play a significant role in revenue generation.
The Random Forest model identified the variables that contributed most to forecasting performance.
The most influential features were:
- Competition Distance
- Store Identification
- Promotional Campaigns (Promo)
- Competition Opening Information
- Time-Based Variables
The results suggest that competitive pressure, store-specific behavior, promotional activities, and temporal patterns are key drivers of sales performance.
Two Machine Learning models were developed and compared:
An ensemble learning algorithm based on decision trees capable of capturing nonlinear relationships and complex sales patterns.
A gradient boosting algorithm optimized for predictive performance and efficiency.
After evaluation, Random Forest achieved the best forecasting performance and was selected as the final model.
The selected forecasting model successfully captured the overall sales trend and recurring seasonal patterns observed in the historical data.
Predicted sales closely followed actual sales throughout the evaluation period, demonstrating the model's ability to generalize to future observations and generate realistic forecasts.
After validation, the final model was applied to the Rossmann test dataset to generate sales predictions for previously unseen observations.
The resulting forecasts were exported as:
sales_forecast_predictions.csv
This simulates a real-world forecasting scenario where future sales must be estimated using only historical information and business-related features.
- Promotional campaigns significantly increase sales performance.
- Competition proximity strongly influences store revenue.
- Individual store characteristics contribute to sales variability.
- Temporal features help capture seasonality and recurring sales patterns.
- Machine Learning can effectively support demand forecasting and business planning.
This project successfully developed a complete sales forecasting pipeline using Machine Learning techniques.
Historical sales data, promotional activities, competition information, and temporal patterns were combined to build predictive models capable of estimating future store sales.
The final Random Forest model demonstrated strong forecasting capability by accurately capturing sales trends and generating realistic predictions for future periods.
These results highlight the value of Machine Learning for:
- Demand Forecasting
- Inventory Planning
- Promotional Strategy Optimization
- Resource Allocation
- Data-Driven Decision Making
Sales-Forecasting/
│
├── data/
│ ├── train.csv
│ ├── store.csv
│ └──test.csv
│
├── images/
│ ├── sales_distribution.png
│ ├── monthly_sales_trend.png
│ ├── promotion_impact.png
│ ├── feature_importance.png
│ └── future_sales_forecast.png
│
├── notebooks/
│ ├── sales_forecasting.ipynb
│ └── sales_forecast_predictions.csv
│
├── README.md
├── requirements.txtTalita Niqian Lin Wu
LinkedIn: https://www.linkedin.com/in/talita-niqian-lin-wu/
GitHub: https://github.com/TalitaNLinWu







