Time Series Forecasting of Daily Sales for Retail Stores Using Facebook Prophet: Incorporating Seasonality, Promotions, Holidays, and Competitive Factors
- Ekramul Haque Towsif
- Dec 30, 2024
- 3 min read
Time series forecasting project leveraging Facebook Prophet to predict daily sales trends for 1115 stores, accounting for seasonality, promotions, holidays, and competition.
Link to Code:
The Problem I Set Out to Solve
As part of a data science project, I worked on a real-world business challenge: predicting daily sales for 1115 retail stores. Sales forecasting is critical for retail businesses as it helps them optimize inventory, plan promotions, and allocate resources efficiently. However, sales are inherently unpredictable due to factors like seasonality, holidays, and promotions.
The goal was to build an accurate forecasting model that accounts for these factors, helping businesses make data-driven decisions. I used Facebook Prophet for time-series forecasting, a tool known for its effectiveness in handling seasonality and external factors.
My Approach
Step 1: Understanding the Data
I began with two key datasets:
Sales Data (train.csv):
Contains daily sales, customer counts, promotional activities, and holiday indicators for 1115 stores.

Sales Data Store Metadata (store.csv):
Includes store-specific details like store type, assortment level, competition distance, and promotional intervals.

Store Information Data
Step 2: Data Cleaning and Preprocessing
Data preparation was a crucial step in ensuring the model's accuracy. Here’s what I did:
Handled Missing Values:
Imputed missing values in CompetitionDistance with the mean.
Filled gaps in promotional data (Promo2SinceWeek, Promo2SinceYear) with zeros for non-participating stores.

Missing Data
Filtered Relevant Data:
Excluded closed stores (using the Open column) as they don’t contribute to sales predictions.
Feature Engineering:
Extracted Year, Month, and Day from the Date column to capture temporal patterns.
Created holiday indicators (StateHoliday, SchoolHoliday) and added them as external regressors.
Step 3: Exploratory Data Analysis (EDA)
EDA helped me uncover trends, correlations, and seasonality in the data:
Trends:
Sales peaked during the Christmas season and dropped on public holidays.
Seasonality:
Weekly and yearly patterns were evident in the sales data.

Correlations:
Sales strongly correlated with customer counts and promotions.
Heatmaps and visualizations showed how external factors impacted sales.
Key Visualizations:
Average Sales by Month:
Sales peaked in December and dropped in February.

Average Sales Per Month
Correlation Heatmap:
Visualized relationships between sales, promotions, and store features.

Correlation Heatmap between Features
Step 4: Model Training with Facebook Prophet
Once the data was prepared, I turned to Facebook Prophet for time-series forecasting:
Setup:
Reformatted the data to include ds (date) and y (sales) columns for Prophet.
Added custom regressors for holidays and promotions.
Training the Model:
Trained Prophet on historical sales data for each store.
Included external factors like state and school holidays to improve accuracy.
Forecasting:
Generated sales predictions for the next 90 days.

Sales Prediction for Next 90 Days for a Specific Store
Step 5: Evaluation
To ensure the model's reliability, I evaluated its performance using:
Mean Absolute Percentage Error (MAPE): 14.2%
Step 6: Results and Insights
The forecasts provided actionable insights:
Seasonality:
The model identified predictable patterns, such as sales increasing on weekends and during holiday seasons.
Promotions:
Sales increased significantly during promotional periods, emphasizing their effectiveness.

Impact of Promotions: Higher sales and customer counts during promotional periods
Holiday Effects:
Sales dipped on certain public holidays, helping businesses anticipate and prepare for these trends.

Forecast Insights
Key Outputs:
Forecasted vs. Actual Sales:
The model closely aligned with actual sales during the test period.
Seasonal Decomposition:
Visualized trends, seasonality, and residuals for deeper understanding.
Step 7: Business Impact
This project demonstrated how data science can transform business operations. With this forecasting model, businesses can:
Optimize Inventory:
Stock up for sales spikes and avoid overstocking during slow periods.
Plan Promotions:
Target promotional campaigns during low-sales periods to boost revenue.
Allocate Resources:
Schedule staff more efficiently, reducing costs and improving service.
Challenges I Faced
Every project has hurdles, and this was no exception:
Missing Data:
Imputed missing values in competition and promotional data to maintain data integrity.
Capturing Holiday Effects:
Created custom regressors for state and school holidays to improve forecast accuracy.
Model Complexity:
Fine-tuned Prophet’s parameters to handle both short-term and long-term trends.





Comments