Skip to main content

What is inventory forecasting? How does it help?

Problem: Retailers struggle to predict demand accurately, especially when external factors like weather dramatically impact sales. Traditional forecasting methods may ignore these contextual signals, leading to stockouts during high-demand periods or excess inventory during low-demand periods. Our approach: Incorporate weather data as context, and demonstrate conditional forecasting to discover which items sell together. Outcome: Our models achieve significantly lower error rates by incorporating weather data, and further analysis reveals which products move together, which can enable strategic decisions like complementary product placement and targeted promotions.

Prerequisites

First, install the required libraries:

1. Load and Prepare Data

We’ll use a real-world dataset from a Chicago store that tracks sales for multiple products along with daily weather conditions. This rich dataset allows us to compare simple time-series forecasting against forecasts that incorporate weather data.

2. Visualize Historical Sales Patterns

Before running forecasts, let’s visualize the historical sales data to understand patterns and seasonality for each product. We’ll create time series plots showing how sales vary over time.
These visualizations help you understand:
  • Sales trends: Are there seasonal patterns or trends over time?
  • Weather impact: How does temperature correlate with sales?
  • Product differences: Do different products show different sensitivities to temperature?

Historical Sales Overview

Historical Sales by Product

Historical Sales and Temperature

Sales vs Temperature Analysis This dual-axis plot reveals the relationship between sales and temperature:
  • Solid colored lines: Sales for each product
  • Dashed red line: Temperature overlay to show how weather affects demand

3. Split Data and Run Forecasts

We’ll split the data and forecast the last 20% of the data to compare univariate vs multivariate forecasting approaches.

4. Visualize Forecast Results

Create visualizations to compare the forecasting approaches:

Example Output: Soup Forecast Comparison

Soup Time Series Forecast Analysis: The multivariate forecast (blue) dramatically outperforms the univariate approach (orange) by capturing weather-related demand fluctuations:
  • Time series plot: The multivariate forecast closely tracks actual sales through various weather conditions, while univariate struggles with sudden changes. The red vertical line marks the train/test split.
  • MAPE values in legend: The legend shows the quantitative improvement - multivariate forecasting achieves significantly lower error rates (MAPE values are displayed directly in the legend labels).
The weather-aware model identifies patterns like increased soup sales during cold, rainy days - insights impossible with time-series-only forecasting.
Note that there seem to be peaks of sales before the weather dips! You can experiment with adding new features like (num_days_before_temp_dip)

Example Output: Tea Forecast Comparison

Tea Time Series Forecast
Key Insight: The multivariate approach doesn’t just forecast better - it reveals why demand changes. By incorporating weather and temporal features, you gain actionable insights: stock more hot beverages before cold fronts, and optimize inventory based on weather forecasts rather than just historical patterns.

5. Easily Find Products that Sell Together

Beyond weather, products in a store often influence each other’s sales. For instance, if coffee sales spike, tea sales might also increase, or soup and bread might move together. We can discover these relationships by using one product’s sales data to help forecast another product’s sales. Knowing this, store owners can introduce promotions or package deals to increase revenue.

What is Cross-Item Analysis

The key insight: if knowing Product A’s sales helps predict Product B’s sales more accurately, then these products are correlated. We measure this by comparing forecast accuracy (MAPE) - lower MAPE means stronger correlation.

What is “Leaking” in Cross-Item Analysis?

In this context, “leaking” refers to conditioning our forecast on another product’s sales data. Think of it as asking: “If I know how much tea was sold today, how does that change my forecast for soup sales?” Example: When we “leak” tea sales data into our soup forecast, we’re essentially asking:
  • Without tea data: “Based on historical soup sales and weather, what will soup sales look like?”
  • With tea data: “Given that tea sales were X units today, and considering historical soup sales and weather, what will soup sales look like?”

How It Works

  1. For each target product (e.g., soup), we forecast its sales using three approaches:
    • Univariate: Time series only
    • Multivariate: Time series + weather
    • Cross-item: Time series + weather + another product’s sales
  2. We test each product as the “leaked” feature to see which one helps most
  3. Lower MAPE = stronger correlation between the products

Visualizing Cross-Item Relationships

Create comprehensive visualizations showing the progressive improvement from univariate to cross-item forecasting:

Example Output: Cross-Item Analysis for Soup

Cross-Item Analysis for Soup Understanding the Analysis:
  • Top panel: Shows the full timeline with historical data and all three forecast approaches. The vertical line marks the train/test split.
  • Bottom panel: Zoomed view of the forecast period showing how each approach performs. Notice the progressive improvement from univariate to multivariate to cross-item forecasting.

Visualizing Cross-Item Prediction Accuracy

Create a comprehensive 2x2 grid showing which items are most helpful for predicting each target item:

Example Output: Cross-Item MAPE Comparison

Cross-Item MAPE Comparison This visualization clearly shows which items are most helpful for predicting each target item:
  • Hot beverages show strong correlations - Tea and Soup are highly correlated
Variable Improvement Across Products: Notice that soup and tea show much larger improvements from cross-item forecasting compared to their baseline univariate/multivariate forecasts. This is because hot beverages and comfort foods have strong weather-driven correlations. In contrast, products like bread may show less dramatic improvement since bread sales are more stable and less influenced by weather patterns. Focus your cross-item forecasting efforts on products that show strong seasonal or weather-related correlations.
Business Applications:
  • Inventory Optimization: If tea and soup are highly correlated, use tea sales trends to improve soup inventory forecasts
  • Shelf Placement: Position correlated products near each other to increase cross-sales
  • Demand Forecasting: When you see unusual tea sales, prepare for corresponding soup demand changes