零售店的需求預測與庫存管理 - 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更易學且易用,C 則更強大但複雜。 1.Python語法簡潔,適合初學者,動態類型和自動內存管理使其易用,但可能導致運行時錯誤。 2.C 提供低級控制和高級特性,適合高性能應用,但學習門檻高,需手動管理內存和類型安全。

每天學習Python兩個小時是否足夠?這取決於你的目標和學習方法。 1)制定清晰的學習計劃,2)選擇合適的學習資源和方法,3)動手實踐和復習鞏固,可以在這段時間內逐步掌握Python的基本知識和高級功能。

Python在開發效率上優於C ,但C 在執行性能上更高。 1.Python的簡潔語法和豐富庫提高開發效率。 2.C 的編譯型特性和硬件控制提升執行性能。選擇時需根據項目需求權衡開發速度與執行效率。

Python和C 各有優勢,選擇應基於項目需求。 1)Python適合快速開發和數據處理,因其簡潔語法和動態類型。 2)C 適用於高性能和系統編程,因其靜態類型和手動內存管理。

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

Python在自動化、腳本編寫和任務管理中表現出色。 1)自動化:通過標準庫如os、shutil實現文件備份。 2)腳本編寫:使用psutil庫監控系統資源。 3)任務管理:利用schedule庫調度任務。 Python的易用性和豐富庫支持使其在這些領域中成為首選工具。

Python在科學計算中的應用包括數據分析、機器學習、數值模擬和可視化。 1.Numpy提供高效的多維數組和數學函數。 2.SciPy擴展Numpy功能,提供優化和線性代數工具。 3.Pandas用於數據處理和分析。 4.Matplotlib用於生成各種圖表和可視化結果。

Python在Web開發中的關鍵應用包括使用Django和Flask框架、API開發、數據分析與可視化、機器學習與AI、以及性能優化。 1.Django和Flask框架:Django適合快速開發複雜應用,Flask適用於小型或高度自定義項目。 2.API開發:使用Flask或DjangoRESTFramework構建RESTfulAPI。 3.數據分析與可視化:利用Python處理數據並通過Web界面展示。 4.機器學習與AI:Python用於構建智能Web應用。 5.性能優化:通過異步編程、緩存和代碼優
