Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Introduction to Demand Forecasting | Inventory Management and Demand Forecasting
Practice
Projects
Quizzes & Challenges
Quizzen
Challenges
/
Python for Supply Chain

bookIntroduction to Demand Forecasting

Veeg om het menu te tonen

Demand forecasting is a critical process in supply chain management. By predicting future demand for products, you can make more informed decisions about inventory levels, production scheduling, and purchasing. Accurate forecasts help reduce stockouts, minimize excess inventory, and ensure that products are available when customers need them. One of the simplest and most widely used techniques for demand forecasting is the moving average method. This approach uses the average of a fixed number of the most recent historical demand values to estimate future demand. The moving average is straightforward to implement and provides a quick way to smooth out short-term fluctuations in demand, making underlying trends easier to spot.

1234567891011121314151617
def moving_average_forecast(demand, window_size): """ Calculate the moving average forecast for a list of demand values. Parameters: demand (list of float): Historical demand data. window_size (int): Number of periods to average. Returns: list of float: Forecasted demand values (same length as input, with None for periods before window is filled). """ forecast = [None] * (window_size - 1) for i in range(window_size - 1, len(demand)): window = demand[i - window_size + 1 : i + 1] avg = sum(window) / window_size forecast.append(avg) return forecast
copy

The moving average method works by averaging a fixed number of the most recent demand points, which helps to smooth out random spikes or dips in the data. By using the moving_average_forecast function above, you can generate a forecast that reacts to changes in demand trends while reducing the impact of outliers or short-term volatility. The longer the window size, the smoother the forecast will be, but it may also become less responsive to recent changes in demand.

12345678910111213141516171819
import matplotlib.pyplot as plt # Sample historical demand data (e.g., weekly demand for a product) demand = [120, 130, 125, 140, 135, 150, 145, 160, 155, 170, 165, 180] # Apply moving average with a window size of 3 window_size = 3 forecast = moving_average_forecast(demand, window_size) # Plot actual vs. forecasted demand plt.figure(figsize=(8, 4)) plt.plot(demand, marker='o', label='Actual Demand') plt.plot(forecast, marker='x', linestyle='--', label='Moving Average Forecast') plt.xlabel('Period') plt.ylabel('Demand') plt.title('Actual vs. Moving Average Forecast') plt.legend() plt.tight_layout() plt.show()
copy

1. What is the main benefit of using a moving average for demand forecasting?

2. How does the window size affect the moving average forecast?

3. Fill in the blank: To calculate the mean of a list in Python, use sum(lst) / ____.

question mark

What is the main benefit of using a moving average for demand forecasting?

Select the correct answer

question mark

How does the window size affect the moving average forecast?

Select the correct answer

question-icon

Fill in the blank: To calculate the mean of a list in Python, use sum(lst) / ____.

sum(lst) /
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 3

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Sectie 2. Hoofdstuk 3
some-alt