摘要
合集:AI案例-ML-零售业
赛题:2021阿里云基础设施供应链大赛-云资源需求预测
主办方:阿里云&阿里巴巴基础设施
主页:https://tianchi.aliyun.com/competition/entrance/531934/introduction
AI问题:时序预测问题
数据集:历史需求数据、当前的库存数据、补货时长以及补货单元的相关信息(产品维度与地理纬度)
数据集价值:达到降低库存成本的目的。
解决方案:基于规则的经验性预测方法
一、赛题描述
无论是互联网还是传统制造业, 供应链都是要考虑的重要问题之一。阿里云具有制造业和互联网的多重属性,提供了一种可随时自助获取、可弹性伸缩、成本保障的云资源服务,而这种弹性能力也给供应链提出了巨大的挑战。另外,根据 IDC数据显示,数据中心成本占比中,服务器占比约70%。为满足客户服务水平同时、并尽可能提高云上资源利用率、降低供应链成本,自动化、智能化的资源规划和供应链管理系统非常关键。供应链精益管理在互联网和云计算的场景下作为新型交叉领域,是工业4.0领域的核心,也是对于学术和工业界都是极具挑战的命题,我们可以通过赛事实现人才发现和引入,并推动产学研结合的创新技术领域的研究。
本次竞赛将聚焦在解决在补货单元纬度(最小库存管理单位),给定过去一段时间的历史需求数据、当前的库存数据、补货时长以及补货单元的相关信息(产品维度与地理纬度),由参赛者结合“时序预测”、“运筹优化”等技术给出相应的库存管理决策,在保证库存大概率满足需求不发生断供的情况下,降低库存率,达到降低库存成本的目的。
二、数据集描述
名词定义
- 库存水位:在仓库存数量,用来满足需求。
- 补货时长(交货时间,lead_time):从下达补货指令到货物到仓可用的时长。本赛题初赛时的补货时长为14天,即假设1号A货物的库存水位为0,此时下达A货物补货指令,补货量为10,则1号至14号A货物的库存水位均为0,15号时A货物的库存水位为10。
- 补货在途:下达补货指令后还未到仓的货物量总和。上例中1号至14号A货物的补货在途为10,其他时段为0。若在8号再次下达补货量为10的补货指令,那么1号至7号的补货在途为10,8号至14号的补货在途为20,15号至21号的补货在途为10,其他时段为0。
- 补货策略:本赛题场景使用周期性盘点的补货策略,每周一为补货决策日,决定货物的补货量。
- 历史需求:货物历史需求量的时间序列,值得注意的是,因为云产品有购买与释放的概念,所以本赛题场景下需求量会为负数,即云产品被用户释放。
- 补货单元:货物的唯一标识。
数据说明
数据文件包括:
- 训练用需求数据(demand_train_A)
- 测试用需求数据(demand_test_A)
- 地理拓扑数据(geo_topo)
- 产品拓扑数据(product_topo)
- 库存信息(inventory_info_A)
- 权重数据(weight_A)
我们会给一个训练集,供训练模型并验证模型效果使用。同时,提供一个测试集,选手需要为按时间读取2021/03/02-2021/06/07的需求数据,并根据历史需求数据以及补货在途,决定补货量,并把决策结果CSV文件输出到指定位置。
由于库存控制是一个前后相关的决策过程,两次补货决策并不独立,因此我们会提供一段时间的数据,由选手在时间轴上进行多次补货决策,最后在较长的时间段内评价选手方案的好坏。脚本需要能根据所得的需求量,根据历史需求数据以及先前所做的决策,决定补货量,并把决策结果CSV文件输出到指定位置。
1、地理拓扑数据
geo_topo_A.csv
geography_level_1 | geography_level_2 | geography_level_3 |
---|---|---|
4dea7c53fb8a8e6a586a89729be2996d | 69d6beffab0807555951e7f947224de3 | fcf14a475e65540c7577370bf438b091 |
3f0cb8b8c238c3b4e08898ce6d449c8d | 692e92669c0ca340eff4fdcef32896ee | 60de5fa40aaaf2850711bc5269f91476 |
860b874ad79c7f2072b4dd24a952f027 | 50fcfda7a3aeb86c6dabc2bd467067b0 | 0b41e006d801550cba4c38157729bf87 |
860b874ad79c7f2072b4dd24a952f027 | e53c88b90c56c50c82ff5293a95fe1b7 | 70b35aead2dac30735d3e5897b287d03 |
860b874ad79c7f2072b4dd24a952f027 | e53c88b90c56c50c82ff5293a95fe1b7 | e37d1fd37c8c4988c46b5152e0d6087d |
860b874ad79c7f2072b4dd24a952f027 | bd8451cc20819e95d08b2e86a9220695 | dd45118031e9d2daafadd23195d04899 |
860b874ad79c7f2072b4dd24a952f027 | bd8451cc20819e95d08b2e86a9220695 | 55704d1433a3abadfcbdd5b0befae53b |
2、产品拓扑数据
product_topo_A.csv
product_level_1 | product_level_2 |
---|---|
3696441120a402f793a704766540e69e | 5cc8015f03554313900f069182bdaf9c |
3696441120a402f793a704766540e69e | ae7d2d22786beebc5981b93c226e2aba |
75688b0220ad16c4e02152b6c2b56424 | 1de8e43efce0cb9161ac2093f75166c8 |
75688b0220ad16c4e02152b6c2b56424 | f517d6345d758010f5782a62b4dfe69b |
75688b0220ad16c4e02152b6c2b56424 | 646f301a50470456f3e7793f6b16ca76 |
75688b0220ad16c4e02152b6c2b56424 | 95feb3e180f99fa2f9908030bc02ac48 |
3、库存信息
inventory_info_A.csv
unit | ts | qty | geography_level | geography | product_level | product | |
---|---|---|---|---|---|---|---|
0 | b035f859cf03840b75abd80dc1cf3e94 | 2021/3/1 | 0 | geography_level_3 | e77f818445598d8b37ebda4c72645900 | product_level_2 | b04c1602cb78c1c4cf72dd7c0ce7d837 |
1 | 828ac2ac9ea800ea61e6c0bf0da57a6f | 2021/3/1 | 0 | geography_level_3 | f05fa82955925441f3a4c9d7092fa5f5 | product_level_2 | b04c1602cb78c1c4cf72dd7c0ce7d837 |
2 | 86fec8ee07c5cf36f259fae08bf1bd14 | 2021/3/1 | 53 | geography_level_3 | cfcb575b4a1fc05255ef88307ffbeaa9 | product_level_2 | be55b932f63b0feda2a190154290d4aa |
3 | 52146622c33726498164d83c10307c01 | 2021/3/1 | 15 | geography_level_3 | e77f818445598d8b37ebda4c72645900 | product_level_2 | be55b932f63b0feda2a190154290d4aa |
4 | ccd0f768f7a21a7fd3530fa0711f2fb1 | 2021/3/1 | 3 | geography_level_3 | cfcb575b4a1fc05255ef88307ffbeaa9 | product_level_2 | b04c1602cb78c1c4cf72dd7c0ce7d837 |
5 | cb853a6f677db7201ebe326ee55a114b | 2021/3/1 | 0 | geography_level_3 | f05fa82955925441f3a4c9d7092fa5f5 | product_level_2 | be55b932f63b0feda2a190154290d4aa |
6 | 5440f09ff5b124a9ac61f2a950c1d31a | 2021/3/1 | 45 | geography_level_3 | 0b41e006d801550cba4c38157729bf87 | product_level_2 | ba569a9ecbaa99645f9baf060d5061e7 |
7 | 85d4470a73f889084197ba909b8d86a7 | 2021/3/1 | 246 | geography_level_3 | f05fa82955925441f3a4c9d7092fa5f5 | product_level_2 | be55b932f63b0feda2a190154290d4aa |
4、训练用需求数据
use_train_A.csv
unit | ts | qty | geography_level | geography | product_level | product | |
---|---|---|---|---|---|---|---|
0 | 9b8f48bacb1a63612f3a210ccc6286cc | 2018/6/4 | 11926.8286 | geography_level_3 | 36ab7b000da26b0547bfc3c3fdf143dc | product_level_2 | 5cc8015f03554313900f069182bdaf9c |
3 | b973094393eae680766fa9db100285af | 2018/6/4 | 6282.726600000001 | geography_level_3 | ec258532d911270434f328606cba61b6 | product_level_2 | 5cc8015f03554313900f069182bdaf9c |
6 | 6d993338e26ab71e9e3f24f52401d67c | 2018/6/4 | 285.3290000000005 | geography_level_3 | 22ec2860549baef5c3e9af46967a3e1d | product_level_2 | 5cc8015f03554313900f069182bdaf9c |
7 | d1dae0ff07a164b729f3c032a21e8e1a | 2018/6/4 | 6672.6452000000045 | geography_level_3 | 50cebc1429231eda4384a84ca4deb751 | product_level_2 | 5cc8015f03554313900f069182bdaf9c |
8 | bf7701bc211c2ecc4314ca02f6ef1cef | 2018/6/4 | 15204.5902 | geography_level_3 | ee0ae2cafd8346e7e74950a6a6271a71 | product_level_2 | 5cc8015f03554313900f069182bdaf9c |
9 | fc136fddfa9df8b0577e9e44c776a5d9 | 2018/6/4 | 7466.050399999999 | geography_level_3 | ee0ae2cafd8346e7e74950a6a6271a71 | product_level_2 | 5cc8015f03554313900f069182bdaf9c |
5、测试用需求数据
use_test_A.csv
unit | ts | qty | geography_level | geography | product_level | product | |
---|---|---|---|---|---|---|---|
0 | 0efede250ca3d05f9d4cc3609242d804 | 2021/3/2 | 3437.199978298611 | geography_level_3 | 7b61250107b0ab94a35b9b80168df40d | product_level_2 | 1de8e43efce0cb9161ac2093f75166c8 |
1 | fbb83aefc6f5d6f6bc22ae3ee757d327 | 2021/3/2 | 34.06792534722222 | geography_level_3 | 8b2bbea7dd24f1427bd37e74936047c7 | product_level_2 | 646f301a50470456f3e7793f6b16ca76 |
2 | 392aaa20e70b4d7539cc7a2e09562521 | 2021/3/2 | 34.85648981730143 | geography_level_3 | e77875a9e01c74e943c9ed3c346d1034 | product_level_2 | b04c1602cb78c1c4cf72dd7c0ce7d837 |
3 | 2effa036807329a88056093fabb07ce6 | 2021/3/2 | 36677.66666666667 | geography_level_3 | 52b9c00ab15c967f2f49c5605800fef5 | product_level_2 | 93a97f63f0a573483d49c58dc02c1341 |
4 | 7dc25ea61b4d47f7de6c7a8d8d559487 | 2021/3/2 | 56688.33333333332 | geography_level_3 | 52b9c00ab15c967f2f49c5605800fef5 | product_level_2 | 6c46c9c5d3ef936b4c8d6d8f9851e837 |
7 | 6580383fbec789022ae6accba82c2be0 | 2021/3/2 | 210 | geography_level_3 | 70b35aead2dac30735d3e5897b287d03 | product_level_2 | ba569a9ecbaa99645f9baf060d5061e7 |
8 | 388744eae278a9988a6f4b950068cdef | 2021/3/2 | 850.5864800347223 | geography_level_3 | c22caf17e6d3e86f4ac0d7a603a4d5a6 | product_level_2 | 1de8e43efce0cb9161ac2093f75166c8 |
数据集版权许可协议
BY-NC-SA 4.0
https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh-hans
三、解决方案样例
思路
源码:Alibaba_Cloud_Infrastructure_Supply_Chain.ipynb
该代码是2021年阿里云基础设施供应链大赛的参赛解决方案,主要目标是实现智能化的库存管理决策,在保证供应不断货的前提下降低库存成本。该源码没有使用传统的预测模型或机器学习框架,而是采用了一种基于规则的经验性预测方法,具体特点如下:
- 无正式预测模型:未使用ARIMA、Prophet、LSTM等时序模型,也未使用scikit-learn等机器学习框架
- 启发式方法:
- 使用前一天的值作为基准(
yesterday_qty
) - 采用14天平移(
shift_14
)作为预测值 - 按周聚合(
weekofyear
)的简单季节性处理
- 使用前一天的值作为基准(
1. 特征变量(输入变量)
代码中实际使用的特征变量相对简单:
- 时间特征:原始时间戳(
ts
)、转换后的日期(dt
)、周数(weekofyear
)、年份(year
)、星期几(dayofweek
) - 标识特征:产品单位(
unit
) – 作为分组依据 - 历史需求数据:
- 前一天的需求量(
yesterday_qty
) - 前一天的变化量(
diff_1 = qty - yesterday_qty
)
- 前一天的需求量(
注:虽然代码加载了geo_topo、product_topo等数据,但实际预测中并未使用这些附加信息。
2. 预测变量(目标变量)
- 主预测变量:
qty
(需求量) - 中间处理变量:
shift_14
: 14天平移后的需求量sum_qty
: 按周聚合后的总需求量
3. 预测方法本质
这种方法本质上是一种”朴素预测”(Naive Forecasting)的变体,结合了以下简单技术:
- 持续性预测:使用最近观测值作为预测值(通过
shift(1)
实现) - 差分处理:计算相邻时间点的变化量(
diff_1
) - 季节性平移:14天平移可能试图捕捉双周模式
- 周聚合:将每日预测汇总为周预测
运行环境
外部库名称 | 版本号 |
---|---|
python | 3.12.8 |
pandas | 2.2.3 |
工作流程
该解决方案主要分为以下几个关键步骤:
1. 数据准备与读取
- 读取多个数据文件:训练需求数据、地理拓扑数据、库存信息、产品拓扑数据和权重数据
- 合并训练集和测试集数据,并按时间排序
- 清理数据(删除无用列,排序等)
demand_train_A = 'data/use_train_A.csv'
geo_topo = 'data/geo_topo_A.csv'
inventory_info_A = 'data/inventory_info_A.csv'
product_topo = 'data/product_topo_A.csv'
weight_A = 'data/weight_A.csv'
demand_train_A = pd.read_csv(demand_train_A)
geo_topo = pd.read_csv(geo_topo)
inventory_info_A = pd.read_csv(inventory_info_A)
product_topo = pd.read_csv(product_topo)
weight_A = pd.read_csv(weight_A)
demand_test_A = 'data/use_test_A.csv'
demand_test_A = pd.read_csv(demand_test_A)
2. 未来需求量预测
代码采用了以下步骤进行需求预测:
- 基础预测:使用简单的时序预测方法:基于历史数据的移动窗口预测
- 使用简单的”昨天值”作为基准预测(yesterday_qty)
- 对测试集中的每个补货单元(unit),计算其需求量与前一天的差异(diff_1)
- 然后使用14天后的差异值作为预测值(shift_14)
- 时间特征提取:
- 将时间戳转换为日期时间类型(dt)
- 提取ISO周数(weekofyear)和年份(year)
- 周聚合:
- 按周、年份和产品单位(unit)聚合需求数据
- 将预测结果按周聚合(每周求和)(sum_qty)
- 结果过滤:
- 只保留每周一(dayofweek=0)的数据
- 使用聚合后的周需求作为最终预测值
submission = demand_test_A
submission['yesterday_qty'] = submission.groupby('unit')['qty'].shift(1).ffill().reset_index().sort_index().set_index('index')
submission['diff_1'] = submission['qty'] - submission['yesterday_qty']
submission['qty'] = submission['diff_1']
submission['shift_14'] = submission.groupby('unit')['qty'].shift(-14).fillna(0).reset_index().sort_index().set_index('index')
submission = submission[['unit', 'ts', 'shift_14']].rename(columns={'shift_14':'qty'})
3. 初始库存消耗计算
- 定义一个
consume_init_inventory
函数,模拟初始库存如何被未来需求消耗
def consume_init_inventory(arr, init_val):
remain = init_val
i = 0
while remain>0 and i<len(arr):
arr[i] = max(0,arr[i]-remain)
remain -= arr[i]
i += 1
return arr
- 对于每个补货单元,根据其初始库存量,逐步扣除预测的未来需求量
- 直到初始库存耗尽或所有未来需求都被满足
init_inventory = inventory_info_A.set_index(['unit'])['qty'].to_dict()
r = []
for i, group in submission.groupby('unit'):
unit = group['unit'].values[0]
init_val = init_inventory[unit]
group = group.sort_values(by='ts')
qty_list = group['qty'].values
qty_list = consume_init_inventory(qty_list, init_val)
group['qty'] = qty_list
r.append(group)
4. 结果输出
- 将最终计算得到的库存消耗预测结果保存为CSV文件
输出到:submission.csv 数据样例
unit | ts | qty |
---|---|---|
00b81e9b086c6b44253d552452b5eaf2 | 2021-03-08 | 51.33333333333326 |
00b81e9b086c6b44253d552452b5eaf2 | 2021-03-15 | 19.33333333333349 |
00b81e9b086c6b44253d552452b5eaf2 | 2021-03-22 | -14.0 |
00b81e9b086c6b44253d552452b5eaf2 | 2021-03-29 | 12.99999999999977 |
00b81e9b086c6b44253d552452b5eaf2 | 2021-04-05 | 16.66666666666674 |
源码开源协议
GPL-v3