クラウド在庫管理コンペティションのベースライン実装

問題定義

主要な概念

  • 在庫レベル: 倉庫に保管されている商品の数量
  • リードタイム: 発注から入庫までの所要時間(本課題では14日間)
  • 発注残: 発注済みだが未入庫の商品数量
  • 補給戦略: 週次発注方式(毎週月曜日に発注決定)
  • 負の需要: クラウドリソースの解放による需要の減少

データ構造

トレーニングデータセット

ファイル名内容
demand_train.csv過去のリソース使用量データ
inventory_info.csv現在の在庫情報
geo_topo.csv地理的階層情報
product_topo.csv製品カテゴリ情報
unit_weight.csv在庫ユニットの重み付け

実装例

データ前処理

import pandas as pd

# データ読み込み
data_files = {
    'demand': 'data/demand_train.csv',
    'inventory': 'data/inventory_info.csv',
    'geo': 'data/geo_topo.csv',
    'product': 'data/product_topo.csv',
    'weight': 'data/unit_weight.csv'
}

dfs = {name: pd.read_csv(path) for name, path in data_files.items()}

# データクリーニング
for df in dfs.values():
    if 'Unnamed: 0' in df.columns:
        df.drop('Unnamed: 0', axis=1, inplace=True)
    if 'ts' in df.columns:
        df.sort_values('ts', inplace=True)

需要予測モデル

def predict_demand(data):
    # 14日先の需要をシフトして予測
    data['future_demand'] = data.groupby('unit')['qty'].shift(-14).fillna(0)
    
    # 週次集計
    data['date'] = pd.to_datetime(data['ts'])
    data['week'] = data['date'].dt.isocalendar().week
    data['year'] = data['date'].dt.year
    
    weekly_data = data.groupby(['year', 'week', 'unit'])['future_demand'].sum().reset_index()
    
    return weekly_data

在庫消費計算

def calculate_inventory_consumption(orders, initial_stock):
    result = []
    
    for unit, group in orders.groupby('unit'):
        current_stock = initial_stock.get(unit, 0)
        demands = group['predicted_qty'].values
        
        for i in range(len(demands)):
            if current_stock <= 0:
                break
            reduction = min(demands[i], current_stock)
            demands[i] -= reduction
            current_stock -= reduction
        
        group['final_order'] = demands
        result.append(group)
    
    return pd.concat(result)

タグ: 在庫管理 需要予測 Python Pandas データ分析

6月16日 19:56 投稿