⭐ 核心三 pillar 时间特征 (年/月/周/日/节假日/促销) · 滞后特征 (Lag) · 滚动窗口统计 (Mean/Std)
| 特征类别 | 典型特征 | 预测作用 | 供应链场景 |
|---|---|---|---|
| ⏳ 时间 | month, week, dayofweek | 季节性、周期性 | 节假日销量高峰 |
| 🎯 滞后 | lag_7, lag_14, lag_30 | 自回归记忆 | 库存补货依赖 |
| 📈 滚动 | rolling_7_mean, rolling_14_std | 局部趋势/波动 | 需求稳定性评估 |
| 📌 事件 | is_holiday, is_promotion | 脉冲影响 | 双十一、黑五 |
# ===== 时间特征 ===== df['year'] = df['date'].dt.year df['month'] = df['date'].dt.month df['week'] = df['date'].dt.isocalendar().week.astype(int) df['dayofweek'] = df['date'].dt.dayofweek df['is_holiday'] = df['date'].isin(holiday_list).astype(int) df['is_promotion'] = df['date'].isin(promotion_dates).astype(int) # ===== 滞后特征 (Lag) ===== df['lag_1'] = df['sales'].shift(1) df['lag_7'] = df['sales'].shift(7) df['lag_30'] = df['sales'].shift(30) df['lag_365'] = df['sales'].shift(365) # 年同比 # ===== 滚动窗口统计 ===== df['rolling_7_mean'] = df['sales'].rolling(window=7).mean() df['rolling_7_std'] = df['sales'].rolling(window=7).std() df['rolling_14_mean'] = df['sales'].rolling(window=14).mean() df['rolling_30_std'] = df['sales'].rolling(window=30).std() # 可选:指数加权移动平均 df['ewm_7'] = df['sales'].ewm(span=7, adjust=False).mean()