Introduction to Demand Forecasting
Glissez pour afficher le menu
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.
1234567891011121314151617def 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
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.
12345678910111213141516171819import 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()
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) / ____.
Merci pour vos commentaires !
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion