Skip to content

Repository files navigation

Demand and Sales Forecasting Project

This repository contains a Demand/Sales Forecasting analysis using the classic Superstore dataset. It demonstrates how to approach a forecasting problem analytically and systematically, going beyond naive model-fitting.

Overview

Amazon and other large-scale retailers run some of the most complex forecasting systems in the world. They don't just throw data into a machine learning model; they understand the temporal nature of their sales.

This project explores a time-series approach to demand forecasting. We cover:

  1. Trend & Seasonality Decomposition: Breaking down the sales signal into underlying trends, seasonal patterns, and residual noise.
  2. Lag Features Construction: Creating historical window features so Machine Learning models can understand temporal context without being strictly autoregressive.
  3. Statistical Baseline vs. Machine Learning: Comparing a naive statistical baseline (Moving Average) against a Machine Learning approach (Random Forest) to prove the value of complex modeling.

Why is this SOP-Worthy?

Most beginners immediately throw XGBoost or LSTMs at tabular sales data without respecting the time axis. This project is Standard Operating Procedure (SOP) worthy because it emphasizes time-series thinking:

  • Avoiding Data Leakage: We split the data temporally (the last 12 months are held out for testing) rather than a random train/test split. Random splits in time-series data lead to data leakage and falsely inflated model performance.
  • Signal Separation: By decomposing the series, we explicitly check for multiplicativity or additivity in seasonality, ensuring that our model doesn't just chase noise.
  • Establishing a Baseline: We implement a 3-month Moving Average. An ML model is only useful if it can beat a cheap, interpretable statistical baseline.
  • Feature Engineering over Raw Data: We explicitly construct lag_1, lag_2, lag_3, and lag_12 features, teaching the ML model about short-term momentum and year-over-year seasonality.

Structure

  • superstore_dataset.csv: The raw dataset containing transaction-level data.
  • forecasting.py: The main Python script that:
    • Aggregates daily transactional data into a robust monthly signal.
    • Performs time-series decomposition.
    • Engineers lag features for the ML model.
    • Runs a Moving Average baseline and a Random Forest Regressor.
    • Outputs evaluation metrics (MAE and RMSE).
  • requirements.txt: Python dependencies required to run the code.

Getting Started

  1. Install the required dependencies:
    pip install -r requirements.txt
  2. Run the forecasting pipeline:
    python forecasting.py

Results and Visualizations

Running the script will automatically generate visualizations:

  • decomposition.png: Shows the extracted trend, seasonal, and residual components.
  • forecast_comparison.png: A side-by-side graphical comparison of the Statistical Baseline vs. the ML Model over the test period.

Concrete Metrics

When tested on the final 12 months of data, the Machine Learning approach heavily outperformed the naive statistical baseline:

  • Moving Average Baseline:

    • MAE: 18,787.40
    • RMSE: 25,181.42
  • Random Forest Model:

    • MAE: 14,280.19
    • RMSE: 16,826.21

By introducing time-series feature engineering (especially the highly predictive lag_12 and month features), the Random Forest reduced RMSE by 33.2% and MAE by 24.0% over the baseline.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages