零售店每天处理大量库存,使得库存监控和管理变得更加繁琐。传统的零售商店库存管理方法繁琐,监控、跟踪和管理效率低下。这就需要一个强大的数字化库存管理系统,该系统可以无缝执行零售商店库存分析,以减少手头库存,并以更少的体力劳动实现更多库存销售。
本文展示了如何使用时间序列机器学习模型 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中文网其他相关文章!

pythonisehybridmodelofcompilationand interpretation:1)thepythoninterspretercompilesourcececodeintoplatform- interpententbybytecode.2)thepytythonvirtualmachine(pvm)thenexecuteCutestestestesteSteSteSteSteSteSthisByTecode,BelancingEaseofuseWithPerformance。

pythonisbothinterpretedAndCompiled.1)它的compiledTobyTecodeForportabilityAcrosplatforms.2)bytecodeisthenInterpreted,允许fordingfordforderynamictynamictymictymictymictyandrapiddefupment,尽管Ititmaybeslowerthananeflowerthanancompiledcompiledlanguages。

在您的知识之际,而foroopsareideal insinAdvance中,而WhileLoopSareBetterForsituations则youneedtoloopuntilaconditionismet

ForboopSareSusedwhenthentheneMberofiterationsiskNownInAdvance,而WhileLoopSareSareDestrationsDepportonAcondition.1)ForloopSareIdealForiteratingOverSequencesLikelistSorarrays.2)whileLeleLooleSuitableApeableableableableableableforscenarioscenarioswhereTheLeTheLeTheLeTeLoopContinusunuesuntilaspecificiccificcificCondond

pythonisnotpuroly interpred; itosisehybridablectofbytecodecompilationandruntimeinterpretation.1)PythonCompiLessourceceCeceDintobyTecode,whitsthenexecececected bytybytybythepythepythepythonvirtirtualmachine(pvm).2)

concateNateListsinpythonwithTheSamelements,使用:1)operatototakeepduplicates,2)asettoremavelemavphicates,or3)listCompreanspearensionforcontroloverduplicates,每个methodhasdhasdifferentperferentperferentperforentperforentperforentperfortenceandordormplications。

pythonisanterpretedlanguage,offeringosofuseandflexibilitybutfacingperformancelanceLimitationsInCricapplications.1)drightingedlanguageslikeLikeLikeLikeLikeLikeLikeLikeThonexecuteline-by-line,允许ImmediaMediaMediaMediaMediaMediateFeedBackAndBackAndRapidPrototypiD.2)compiledLanguagesLanguagesLagagesLikagesLikec/c thresst

Useforloopswhenthenumberofiterationsisknowninadvance,andwhileloopswheniterationsdependonacondition.1)Forloopsareidealforsequenceslikelistsorranges.2)Whileloopssuitscenarioswheretheloopcontinuesuntilaspecificconditionismet,usefulforuserinputsoralgorit


热AI工具

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

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

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

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

热门文章

热工具

Atom编辑器mac版下载
最流行的的开源编辑器

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

Dreamweaver CS6
视觉化网页开发工具

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中