Giao diện
Feature Engineering
TÓM TẮT
FeatureEngineer (core/features.py, ~407 dòng) tạo 40+ features từ raw transaction data. Các features được nhóm thành 11 categories.
Bảng Features đầy đủ
1. Temporal Features (7)
| Feature | Mô tả |
|---|---|
dow | Day of week (0-6) |
dom | Day of month (1-31) |
is_weekend | Thứ 7 / Chủ nhật |
is_start | Đầu tháng (ngày 1-3) |
is_end | Cuối tháng (ngày 28-31) |
week_of_month | Tuần trong tháng (1-5) |
days_to_month_end | Số ngày đến cuối tháng |
2. Event Features (6)
| Feature | Mô tả |
|---|---|
event_tier | Mức sự kiện (0-3) |
is_payday_window | Trong window ngày lương |
is_mid_month | Giữa tháng |
is_holiday | Ngày lễ |
event_day_weight | Trọng số event (multiplier) |
is_event_day | Có event hay không |
3. Event Proximity Features (4)
| Feature | Mô tả |
|---|---|
days_to_next_tier1 | Số ngày đến event tier 1 tiếp theo |
days_since_last_tier1 | Số ngày từ event tier 1 gần nhất |
days_to_next_event | Số ngày đến event tiếp theo |
days_since_last_event | Số ngày từ event gần nhất |
4. Lag Features (7)
| Feature | Mô tả |
|---|---|
lag_1 → lag_56 | Chuỗi lag: 1, 2, 3, 7, 14, 28, 56 ngày |
5. Rolling Window Features (3)
| Feature | Mô tả |
|---|---|
roll_7 | Moving average 7 ngày |
roll_14 | Moving average 14 ngày |
roll_28 | Moving average 28 ngày |
6. Event-Masked Rolling (3)
ĐẶC BIỆT
Rolling mean loại trừ event days để tránh spike contamination vào baseline.
| Feature | Mô tả |
|---|---|
roll_7_masked | MA 7 ngày (không tính event days) |
roll_14_masked | MA 14 ngày (không tính event days) |
roll_28_masked | MA 28 ngày (không tính event days) |
7. Exponentially Weighted Mean (2)
| Feature | Mô tả |
|---|---|
ewm_7 | EWM span 7 ngày |
ewm_14 | EWM span 14 ngày |
8. Same-Event Lag (2)
| Feature | Mô tả |
|---|---|
same_event_lag | Volume cùng event năm trước (VD: 11.11.2025 → 11.11.2024) |
same_event_lag_2y | Volume cùng event 2 năm trước |
9. Intermittent Demand (3)
| Feature | Mô tả |
|---|---|
demand_frequency | Tần suất có demand (0-1) |
days_since_last | Số ngày từ lần có demand gần nhất |
zero_streak | Chuỗi liên tiếp demand = 0 |
10. Discount & Scaling (3)
| Feature | Mô tả |
|---|---|
discount_ratio | Tỷ lệ giảm giá |
discount_ratio_7d | Tỷ lệ giảm giá 7 ngày gần nhất |
base_demand | Non-event mean (cho cross-learning) |
11. SKU Classification (5+)
| Feature | Mô tả |
|---|---|
sku_type | dead / intermittent / lumpy / smooth / seasonal |
is_dead, is_intermittent, etc. | Binary flags |
channel_count | Số kênh bán |
user_diversity | Số users mua |
recent_sales_30d | Tổng bán 30 ngày gần nhất |
Pipeline Flow
python
# Trong ForecastPipeline
features_df = FeatureEngineer.create_all_features(
df=daily_aggregated_data,
calendar=event_calendar
)
# Output: DataFrame với tất cả 40+ features + target columnHIỆU NĂNG
expand_dates() có thể gây memory pressure cho dataset lớn (10,000 SKUs × 730 ngày = 7.3M rows). Xem IMP-06.
Tài liệu liên quan
- DemandForecastModel — Model sử dụng features này
- Calendar & Events — Event calendar chi tiết
- Pipeline — Orchestration flow