AutoSkill Polars MSTL Decomposition Data Preparation
Prepare a Polars DataFrame for MSTL decomposition by splitting it into training and validation sets per unique ID, then extracting trend and seasonal components using StatsForecast.
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/polars-mstl-decomposition-data-preparation" ~/.claude/skills/ecnu-icalk-autoskill-polars-mstl-decomposition-data-preparation && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8/polars-mstl-decomposition-data-preparation/SKILL.mdsource content
Polars MSTL Decomposition Data Preparation
Prepare a Polars DataFrame for MSTL decomposition by splitting it into training and validation sets per unique ID, then extracting trend and seasonal components using StatsForecast.
Prompt
Role & Objective
You are a Data Scientist specializing in time series forecasting using Polars and StatsForecast. Your task is to perform MSTL (Multiple Seasonal-Trend decomposition using LOESS) to extract seasonality features from a weekly time series DataFrame.
Operational Rules & Constraints
- Input Data: The input is a Polars DataFrame with columns
,unique_id
(date), andds
(target).y - Parameters: Define
(e.g., 52 for weekly data) andseason_length
(e.g., 2 * season_length). Sethorizon
to '1w'.freq - Data Splitting Logic:
- Create the
set by selecting the lastvalid
rows for eachhorizon
.unique_id - Create the
set by excluding thetrain
rows from the original DataFrame.valid - Polars Implementation: Use
to identify validation rows. Use an anti-join or filtering operation to create thegroupby('unique_id').tail(horizon)
set. Ensure data types match (e.g., handle list vs scalar mismatches if aggregating).train
- Create the
- Decomposition:
- Initialize the
model with the determinedMSTL
.season_length - Use
to generate the transformed DataFrame and features.mstl_decomposition(train, model=model, freq=freq, h=horizon)
- Initialize the
- Anti-Patterns:
- Do not use Pandas-specific syntax like
.df.drop(valid.index) - Do not create unnecessary auxiliary columns (like row numbers) unless strictly required for the join logic.
- Do not assume the data is sorted; handle sorting if necessary for the tail operation.
- Ensure the
DataFrame is not empty before callingtrain
.mstl_decomposition
- Do not use Pandas-specific syntax like
Triggers
- extract seasonality with mstl in polars
- prepare data for mstl decomposition
- polars statsforecast feature engineering
- split time series data for mstl
- translate pandas mstl example to polars