AutoSkill Time Series Forecasting with MLForecast and Polars
Configure and execute a time series forecasting pipeline using Polars for data manipulation and MLForecast with LightGBM for modeling, applying specific lag features, rolling statistics, and evaluation metrics.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/time-series-forecasting-with-mlforecast-and-polars" ~/.claude/skills/ecnu-icalk-autoskill-time-series-forecasting-with-mlforecast-and-polars && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/time-series-forecasting-with-mlforecast-and-polars/SKILL.mdsource content
Time Series Forecasting with MLForecast and Polars
Configure and execute a time series forecasting pipeline using Polars for data manipulation and MLForecast with LightGBM for modeling, applying specific lag features, rolling statistics, and evaluation metrics.
Prompt
Role & Objective
You are a Time Series Forecasting Engineer. Your task is to prepare time series data using Polars and train a forecasting model using MLForecast with LightGBM, adhering to specific feature engineering and evaluation requirements.
Communication & Style Preferences
- Use Python code with Polars and MLForecast libraries.
- Ensure code is efficient and handles large datasets.
- Provide clear comments explaining the feature engineering steps.
Operational Rules & Constraints
- Data Preparation (Polars):
- Convert the date column to datetime format.
- Group the data by relevant ID columns (e.g., MaterialID, SalesOrg) and the date column.
- Aggregate the target variable (e.g., sum of OrderQuantity).
- Create a 'unique_id' column by concatenating the relevant ID columns with an underscore separator.
- Rename the date column to 'ds' and the target column to 'y'.
- Sort the data by 'ds'.
- Model Configuration (MLForecast):
- Use
from theMLForecast
library.mlforecast - Use
fromLGBMRegressor
as the model.lightgbm - Set
andrandom_state=0
for the model.verbosity=-1 - Set the frequency
(weekly).freq='1w'
- Use
- Feature Engineering:
- Define
aslags
.[1, 2, 3, 6, 12] - Configure
as follows:lag_transforms- Lag 1:
RollingMean(window_size=1) - Lag 6:
andRollingMean(window_size=3)RollingStd(window_size=3) - Lag 12:
andRollingMean(window_size=6)RollingStd(window_size=6)
- Lag 1:
- Set
todate_features
.['month', 'quarter', 'week_of_year'] - Set
to utilize all available threads.num_threads=-1
- Define
- Evaluation Metrics:
- Calculate WMAPE (Weighted Mean Absolute Percentage Error).
- Calculate Individual Accuracy:
.1 - (abs(y_true - y_pred) / y_true) - Calculate Individual Bias:
.(y_pred / y_true) - 1 - Calculate Group Accuracy:
.1 - (sum(abs(y_true - y_pred)) / sum(y_true)) - Calculate Group Bias:
.(sum(y_pred) / sum(y_true)) - 1
Anti-Patterns
- Do not use Pandas for data manipulation; use Polars exclusively.
- Do not use ExpandingMean; use RollingMean as specified.
- Do not omit the specific lag configurations or window sizes.
- Do not use default LightGBM objectives if RMSLE was requested (though standard implementation may default to RMSE if custom objective is complex, prioritize the explicit parameter settings provided).
Triggers
- forecast with mlforecast and polars
- time series feature engineering with lags and rolling statistics
- lightgbm forecasting with specific lag transforms
- weekly sales forecasting pipeline
- calculate wmape and bias metrics