零售店的需求预测和库存管理 - SARIMA 模型
零售店每天处理大量库存,使得库存监控和管理变得更加繁琐。传统的零售商店库存管理方法繁琐,监控、跟踪和管理效率低下。这就需要一个强大的数字化库存管理系统,该系统可以无缝执行零售商店库存分析,以减少手头库存,并以更少的体力劳动实现更多库存销售。
本文展示了如何使用时间序列机器学习模型 SARIMA 来高效地执行零售商店库存分析,并计算随着时间的推移满足客户需求所需的库存参数,从而使零售商店获得最大利润。
数据集
首先,下载数据集。该数据集包含特定产品的历史记录,包括日期、产品需求和当前库存水平等信息。
代码
执行需求预测和库存管理的Python代码如下。
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)
理解代码
我们首先可视化“一段时间内的需求”和“一段时间内的库存”,从中可以观察到季节性模式。因此我们使用 SARIMA——季节性自回归移动平均线来预测需求。
要使用 SARIMA,我们需要 p(自回归阶数)、d(差分度)、q(移动平均阶数)、P(季节性 AR 阶数)、D(季节性差分)和 Q(季节性 MA 阶数) 。绘制 ACF — 自相关函数和 PACF — 偏自相关函数来查找参数值。
现在为了预测,我们初始化一些值。我们将未来步骤(即预测天数)设置为 10,提前期(即补充库存的天数)设置为 1 以及其他此类零售商店相关值。
最后为了计算库存最优结果,我们使用NewsVendor公式。 NewsVendor 公式源自 NewsVendor 模型,NewsVendor 模型是用于确定最佳库存水平的数学模型。您可以从本文中了解有关 NewsVendor 公式的更多信息。
最终评估结果是,
- 最佳订购数量 — 指当库存水平达到某一点时应向供应商订购产品的数量。
- 再订购点 — 在库存耗尽之前应下新订单以补充库存的库存水平。
- 安全库存——手头保留额外库存,以应对需求和供应的不确定性。它可以作为需求或交货时间意外变化的缓冲。
- 总成本 — 表示与库存管理相关的综合成本。
提出的 SARIMA 模型使用 Newsvendor 公式以有效的方式将零售商店库存管理数字化,以计算满足客户需求所需的最佳库存,同时使零售商获得最大利润。
希望这篇文章可以帮助您找到您想要的东西。欢迎对本文提出任何改进或建议。干杯:)
在这里查看我的社交并随时联系^_^
以上是零售店的需求预测和库存管理 - SARIMA 模型的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

Python适合数据科学、Web开发和自动化任务,而C 适用于系统编程、游戏开发和嵌入式系统。 Python以简洁和强大的生态系统着称,C 则以高性能和底层控制能力闻名。

Python在游戏和GUI开发中表现出色。1)游戏开发使用Pygame,提供绘图、音频等功能,适合创建2D游戏。2)GUI开发可选择Tkinter或PyQt,Tkinter简单易用,PyQt功能丰富,适合专业开发。

Python更易学且易用,C 则更强大但复杂。1.Python语法简洁,适合初学者,动态类型和自动内存管理使其易用,但可能导致运行时错误。2.C 提供低级控制和高级特性,适合高性能应用,但学习门槛高,需手动管理内存和类型安全。

要在有限的时间内最大化学习Python的效率,可以使用Python的datetime、time和schedule模块。1.datetime模块用于记录和规划学习时间。2.time模块帮助设置学习和休息时间。3.schedule模块自动化安排每周学习任务。

Python在开发效率上优于C ,但C 在执行性能上更高。1.Python的简洁语法和丰富库提高开发效率。2.C 的编译型特性和硬件控制提升执行性能。选择时需根据项目需求权衡开发速度与执行效率。

pythonlistsarepartofthestAndArdLibrary,herilearRaysarenot.listsarebuilt-In,多功能,和Rused ForStoringCollections,而EasaraySaraySaraySaraysaraySaraySaraysaraySaraysarrayModuleandleandleandlesscommonlyusedDduetolimitedFunctionalityFunctionalityFunctionality。

每天学习Python两个小时是否足够?这取决于你的目标和学习方法。1)制定清晰的学习计划,2)选择合适的学习资源和方法,3)动手实践和复习巩固,可以在这段时间内逐步掌握Python的基本知识和高级功能。

Python在自动化、脚本编写和任务管理中表现出色。1)自动化:通过标准库如os、shutil实现文件备份。2)脚本编写:使用psutil库监控系统资源。3)任务管理:利用schedule库调度任务。Python的易用性和丰富库支持使其在这些领域中成为首选工具。
