Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- time-series-forecasting
|
| 4 |
+
- multivariate-forecasting
|
| 5 |
+
- transformer
|
| 6 |
+
- e-commerce
|
| 7 |
+
- inventory-management
|
| 8 |
+
datasets:
|
| 9 |
+
- EcomSalesPerformance
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# EcomSalesTrendPredictor
|
| 14 |
+
|
| 15 |
+
## 📈 Overview
|
| 16 |
+
|
| 17 |
+
EcomSalesTrendPredictor is a **Time Series Transformer** model designed for **multivariate forecasting** of e-commerce sales performance metrics. Specifically, it is trained to predict future `Revenue_USD` and `UnitsSold` (implicitly handled as separate series during training, or focused on one primary series like `Revenue_USD` as `input_size=1` for simplicity) for multiple product SKUs across various regions.
|
| 18 |
+
|
| 19 |
+
The model incorporates numerous real-world contextual features, including static (e.g., product category, region) and dynamic (e.g., promotion status, season, inventory level) variables, making it highly robust for complex supply chain and financial planning tasks.
|
| 20 |
+
|
| 21 |
+
## 🧠 Model Architecture
|
| 22 |
+
|
| 23 |
+
This model utilizes the **Time Series Transformer (TST)** architecture, which is state-of-the-art for sequence modeling tasks due to its use of self-attention mechanisms.
|
| 24 |
+
|
| 25 |
+
* **Model Type:** `TimeSeriesTransformerModel` (from HuggingFace's transformers/pytorch-forecasting implementation).
|
| 26 |
+
* **Input:** Multiple time series (each SKU/Region combination is a series) of historical data for the target metric (`Revenue_USD` or `UnitsSold`).
|
| 27 |
+
* **Context/Prediction:** Uses a `context_length` of 30 days of historical data to predict the next `prediction_length` of 7 days.
|
| 28 |
+
* **Feature Integration:**
|
| 29 |
+
* **Static Categorical:** Region, ProductCategory, SKU (embedded).
|
| 30 |
+
* **Static Real:** Log of average CustomerRating, Shipping Cost.
|
| 31 |
+
* **Dynamic Real:** Inventory_Level, DaysSinceLastRestock, InventoryRiskScore.
|
| 32 |
+
* **Dynamic Categorical:** PromotionApplied, Season.
|
| 33 |
+
* **Output:** The model outputs a set of **quantiles** (0.1, 0.5, 0.9) for the forecast, providing an uncertainty range rather than a single point estimate.
|
| 34 |
+
|
| 35 |
+
## 🚀 Intended Use
|
| 36 |
+
|
| 37 |
+
* **Sales Forecasting:** Predict weekly revenue and unit sales for better financial planning.
|
| 38 |
+
* **Inventory Optimization:** Use the 7-day forecast to trigger restocking orders, minimizing stockouts (high `InventoryRiskScore`) or excess inventory.
|
| 39 |
+
* **Demand Planning:** Analyze the impact of dynamic features (promotions, season) on future demand.
|
| 40 |
+
* **Multi-Region Strategy:** Compare and predict performance across different geographic regions simultaneously.
|
| 41 |
+
|
| 42 |
+
## ⚠️ Limitations
|
| 43 |
+
|
| 44 |
+
* **Data Density:** Performance may degrade if the input time series contains large gaps or is highly irregular.
|
| 45 |
+
* **External Shocks:** Like all time-series models, it cannot predict sudden, unforeseen external events (e.g., pandemics, major news events) that significantly disrupt market patterns.
|
| 46 |
+
* **Computational Cost:** Transformer-based models are more computationally expensive than simpler models (like ARIMA) for both training and inference.
|
| 47 |
+
* **SKU Limit:** The model is implicitly limited by the SKU cardinality it was trained on; adding entirely new products requires retraining or fine-tuning.
|
| 48 |
+
|
| 49 |
+
## 💻 Example Code
|
| 50 |
+
|
| 51 |
+
To use the model for forecasting (requires a compatible time series library like `pytorch-forecasting`):
|
| 52 |
+
|
| 53 |
+
```python
|
| 54 |
+
import pandas as pd
|
| 55 |
+
from transformers import AutoModel
|
| 56 |
+
from pytorch_forecasting import TimeSeriesDataSet, DeepAR
|
| 57 |
+
|
| 58 |
+
# NOTE: Actual inference with TST requires full PyTorch Forecasting setup.
|
| 59 |
+
# This example illustrates the data preparation steps.
|
| 60 |
+
|
| 61 |
+
model_name = "your-username/EcomSalesTrendPredictor" # Replace with actual HuggingFace path
|
| 62 |
+
# model = AutoModel.from_pretrained(model_name)
|
| 63 |
+
|
| 64 |
+
# Example historical data for one series (truncated for simplicity)
|
| 65 |
+
data = {
|
| 66 |
+
'time_idx': [1, 2, 3, 4, 5],
|
| 67 |
+
'target': [34995.0, 3600.0, 937.5, 18750.0, 2700.0],
|
| 68 |
+
'series': ['EL-LAP-001'] * 5,
|
| 69 |
+
'Region': ['North America'] * 5,
|
| 70 |
+
'ProductCategory': ['Electronics'] * 5,
|
| 71 |
+
'UnitsSold': [45, 180, 75, 15, 90],
|
| 72 |
+
'Inventory_Level': [120, 500, 90, 40, 300],
|
| 73 |
+
'PromotionApplied': [0, 1, 0, 0, 1]
|
| 74 |
+
}
|
| 75 |
+
df = pd.DataFrame(data)
|
| 76 |
+
|
| 77 |
+
# The loaded model object expects a TimeSeriesDataSet object for inference.
|
| 78 |
+
# The TST is highly dependent on the correct feature schema defined in its config.
|
| 79 |
+
print(f"Model configured for a prediction length of {model_config.prediction_length} days.")
|
| 80 |
+
print("Inference requires pre-processing the data into a TimeSeriesDataSet format.")
|