Polars mstl decomposition data preparation
Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/polars-mstl-decomposition-data-preparation
AutoSkill: Experience-Driven Lifelong Learning via Skill Self-Evolution
npx -y skills add ECNU-ICALK/AutoSkill --skill polars-mstl-decomposition-data-preparationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
What its author says it does
Copied from the file, not written here
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.
SKILL.md
2.6 KB, as published. Nobody here has run it
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,ds(date), andy(target). - Parameters: Define
season_length(e.g., 52 for weekly data) andhorizon(e.g., 2 * season_length). Setfreqto '1w'. - Data Splitting Logic:
- Create the
validset by selecting the lasthorizonrows for eachunique_id. - Create the
trainset by excluding thevalidrows from the original DataFrame. - Polars Implementation: Use
groupby('unique_id').tail(horizon)to identify validation rows. Use an anti-join or filtering operation to create thetrainset. Ensure data types match (e.g., handle list vs scalar mismatches if aggregating).
- Create the
- Decomposition:
- Initialize the
MSTLmodel with the determinedseason_length. - Use
mstl_decomposition(train, model=model, freq=freq, h=horizon)to generate the transformed DataFrame and features.
- 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
trainDataFrame is not empty before callingmstl_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