Time Series Forecasting of Daily Sales for Retail Stores Using Facebook Prophet: Incorporating Seasonality, Promotions, Holidays, and Competitive Factors
Time series forecasting project leveraging Facebook Prophet to predict daily sales trends for 1115 stores, accounting for seasonality, promotions, holidays, and competition.
Accurate sales forecasting is essential for businesses to optimize operations and plan future strategies. This project builds predictive models to forecast future sales based on historical data, enabling better decision-making in competitive environments.
https://www.kaggle.com/c/rossmann-store-sales/data
Sales Data: Sales, customers, promotions, and holidays.
Store Attributes: StoreType, Assortment, CompetitionDistance, and more.
Temporal Features: Holidays, school closures, promotional intervals.
Facebook Prophet:
Designed for time series data with seasonal effects.
Incorporates yearly, weekly, daily seasonality, and holiday effects.
Open-source software for scalable forecasting.
EDA is a critical phase in the project, helping us understand the data, identify trends, and prepare it for modeling. The following steps were carried out:
Loaded datasets train.csv and store.csv. Reviewed the structure, types, and sample entries of each dataset. Identified key features like Sales, Promo, StateHoliday, Customers, and store metadata.
Checked for missing values and handled them: For CompetitionDistance, missing values were imputed with a default value or the median. For promotional variables (Promo2 and related features), filled missing values with "0" or "No Promo." Converted Date to a proper datetime format for time-series analysis.
Time-series plots to observe sales trends over time. Boxplots to visualize the distribution of sales across different store types (StoreType, Assortment). Correlation heatmaps to identify relationships between variables.
Analyzed the relationship between Sales and: Customers: Strong correlation observed. Promo and Promo2: Sales were higher during promotions. Holidays (StateHoliday, SchoolHoliday): Significant variations in sales.
Decomposed the sales time series into components (trend, seasonality, and residuals). Observed yearly and weekly seasonality patterns, along with periodic spikes during holidays.
The training phase involves building a time-series model using Facebook Prophet:
Filtered the dataset to focus on relevant columns: ds (Date) and y (Sales) for Prophet. Merged the sales data with store metadata to incorporate additional features like promotions and holidays. Scaled/normalized data where necessary to handle variations.
Configured Prophet for: Trend Analysis: Capturing the long-term upward or downward trend in sales. Seasonality: Adding yearly, weekly, and daily seasonal components. Holiday Effects: Included state and school holidays as regressors. Split the data into training and test sets to evaluate performance.
Adjusted Prophet’s hyperparameters, such as: Changepoint Prior Scale: To control flexibility in trend changes. Seasonality Prior Scale: To emphasize or reduce seasonality effects. Fine-tuned holiday-specific effects using additional regressors.
Trained Prophet on the historical sales data to capture underlying patterns. Incorporated external features like Promo, CompetitionDistance, and PromoInterval using custom regressors.
The prediction phase involves forecasting future sales and evaluating model performance:
Generated sales forecasts for the test set using the trained Prophet model.
Predicted values included:
Point estimates (yhat).
Uncertainty intervals (yhat_lower, yhat_upper).
Compared predicted sales (yhat) against actual sales from the test set. Calculated metrics:
MAPE (Mean Absolute Percentage Error): To express error as a percentage.
The model accurately captured sales spikes during promotions and holidays. Uncertainty intervals provided confidence ranges for predictions, ensuring reliability in decision-making.
Plotted actual vs. predicted sales to assess performance visually. Residual plots revealed any patterns in prediction errors, ensuring no systemic biases
To clone this project, run
git clone https://github.com/ekramul14/Sales-Forecasting-With-Prophet.git
cd Sales-Forecasting-With-Prophet
Install Dependencies
pip install -r requirements.txt


