Home Backend Development Python Tutorial Demand Forecasting and Inventory Management in Retail Store - SARIMA Model

Demand Forecasting and Inventory Management in Retail Store - SARIMA Model

Nov 27, 2024 am 04:21 AM

The retail store handles stock on a large scale daily, making monitoring and managing the inventory more tedious. Traditional retail store inventory management is a cumbersome methodology with inefficient monitoring, tracking and management. This brings in the need for a robust digitized inventory management system that seamlessly performs retail store stock analytics to achieve less inventory on hand and more stocks on sale with less manual labor.

This article shows how SARIMA, a time series machine learning model can be used to efficiently perform retail store stock inventory analysis and calculate the inventory parameter needed to cater to the needs of customers over time benefitting the retail store with maximum profit.

Demand Forecasting and Inventory Management in Retail Store - SARIMA Model


DATASET

To begin with, download the dataset. This dataset has historical record of a specific product which includes information on the date, product demand and current inventory levels.


CODE

The Python code for performing the demand forecasting and inventory management is as below.

import pandas as pd
import numpy as np
import plotly.express as px
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
import matplotlib.pyplot as plt
from statsmodels.tsa.statespace.sarimax import SARIMAX

data = pd.read_csv("demand_inventory.csv")
print(data.head())

data = data.drop(columns=['Unnamed: 0'])

fig_demand = px.line(data, x='Date', y='Demand', title='Demand Over Time')
fig_demand.show()

fig_inventory = px.line(data, x='Date', y='Inventory', title='Inventory Over Time')
fig_inventory.show()

data['Date'] = pd.to_datetime(data['Date'], format='%Y/%m/%d')
time_series = data.set_index('Date')['Demand']

differenced_series = time_series.diff().dropna()

# Plot ACF and PACF of differenced time series
fig, axes = plt.subplots(1, 2, figsize=(12, 4))
plot_acf(differenced_series, ax=axes[0])
plot_pacf(differenced_series, ax=axes[1])
plt.show()

order = (1, 1, 1)
seasonal_order = (1, 1, 1, 2)
model = SARIMAX(time_series, order=order, seasonal_order=seasonal_order)
model_fit = model.fit(disp=False)
future_steps = 10
predictions = model_fit.predict(len(time_series), len(time_series) + future_steps - 1)
predictions = predictions.astype(int)
print(predictions)

# Create date indices for the future predictions
future_dates = pd.date_range(start=time_series.index[-1] + pd.DateOffset(days=1), periods=future_steps, freq='D')

# Create a pandas Series with the predicted values and date indices
forecasted_demand = pd.Series(predictions, index=future_dates)

# Initial inventory level
initial_inventory = 5500

# Lead time (number of days it takes to replenish inventory)
lead_time = 1

# Service level (probability of not stocking out)
service_level = 0.95

# Calculate the optimal order quantity using the Newsvendor formula
z = np.abs(np.percentile(forecasted_demand, 100 * (1 - service_level)))
order_quantity = np.ceil(forecasted_demand.mean() + z).astype(int)

# Calculate the reorder point
reorder_point = forecasted_demand.mean() * lead_time + z

# Calculate the optimal safety stock
safety_stock = reorder_point - forecasted_demand.mean() * lead_time

# Calculate the total cost (holding cost + stockout cost)
holding_cost = 0.1  # it's different for every business, 0.1 is an example
stockout_cost = 10  # # it's different for every business, 10 is an example
total_holding_cost = holding_cost * (initial_inventory + 0.5 * order_quantity)
total_stockout_cost = stockout_cost * np.maximum(0, forecasted_demand.mean() * lead_time - initial_inventory)

# Calculate the total cost
total_cost = total_holding_cost + total_stockout_cost

print("Optimal Order Quantity:", order_quantity)
print("Reorder Point:", reorder_point)
print("Safety Stock:", safety_stock)
print("Total Cost:", total_cost)
Copy after login

UNDERSTANDING THE CODE

We start with visualizing the ‘Demand over time’ and ‘Inventory over time’ from which a seasonal pattern can be observed. So we use SARIMA — Seasonal Autoregressive Moving Average to forecast the demand.

To use SARIMA we need p (auto-regressive order), d (degree of differencing), q (moving-average order), P (seasonal AR order), D (seasonal differencing) and Q (seasonal MA order). ACF — Autocorrelation function and PACF — Partial Autocorrelation function are plotted to find the parameter values.

Now to forecast we initialize few values. We set future steps i.e. days to forecast as 10, lead time i.e. number of days to replenish the inventory as 1 and other such retail store dependent values.

Finally to calculate inventory optimal result, we use NewsVendor formula. NewsVendor formula is derived from NewsVendor model which is a mathematical model used to determine optimal inventory level. You can learn more about NewsVendor formula from this article.

The final results evaluated are,

  1. Optimal order quantity — Refers to the quantity of a product that should be ordered from suppliers when the inventory level reaches a certain point.
  2. Reorder point — The inventory level at which a new order should be placed to replenish stock before it runs out.
  3. Safety stock — Additional inventory kept on hand to account for uncertainties in demand and supply. It acts as a buffer against unexpected variations in demand or lead time.
  4. Total cost — Represents the combined costs associated with inventory management.

The proposed SARIMA model digitized the retail store stock inventory management in an efficient way using the Newsvendor formula to calculate the optimal inventory needed to fulfill the customers while benefiting the retailers with maximum profit.


Hope this article may have helped you with what you were looking for. Any improvements or suggestions for the article are welcome. Cheers :)

Checkout my socials here and feel free to connect ^_^

The above is the detailed content of Demand Forecasting and Inventory Management in Retail Store - SARIMA Model. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1242
24
Python vs. C  : Applications and Use Cases Compared Python vs. C : Applications and Use Cases Compared Apr 12, 2025 am 12:01 AM

Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

Python: Games, GUIs, and More Python: Games, GUIs, and More Apr 13, 2025 am 12:14 AM

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

The 2-Hour Python Plan: A Realistic Approach The 2-Hour Python Plan: A Realistic Approach Apr 11, 2025 am 12:04 AM

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python vs. C  : Learning Curves and Ease of Use Python vs. C : Learning Curves and Ease of Use Apr 19, 2025 am 12:20 AM

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

How Much Python Can You Learn in 2 Hours? How Much Python Can You Learn in 2 Hours? Apr 09, 2025 pm 04:33 PM

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

Python and Time: Making the Most of Your Study Time Python and Time: Making the Most of Your Study Time Apr 14, 2025 am 12:02 AM

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python: Automation, Scripting, and Task Management Python: Automation, Scripting, and Task Management Apr 16, 2025 am 12:14 AM

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.

Python: Exploring Its Primary Applications Python: Exploring Its Primary Applications Apr 10, 2025 am 09:41 AM

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

See all articles