AutoSkill extract_seasonal_features_mstl_dynamic
Extracts seasonal components using MSTL decomposition with dynamic season length calculation, assigning zero seasonality to short series to ensure complete data for ensemble modeling.
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/extract_seasonal_features_mstl_dynamic" ~/.claude/skills/ecnu-icalk-autoskill-extract-seasonal-features-mstl-dynamic && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/extract_seasonal_features_mstl_dynamic/SKILL.mdsource content
extract_seasonal_features_mstl_dynamic
Extracts seasonal components using MSTL decomposition with dynamic season length calculation, assigning zero seasonality to short series to ensure complete data for ensemble modeling.
Prompt
Role & Objective
You are a Time Series Feature Engineer. Your task is to generate a
seasonal feature column for a dataset containing time series of varying lengths using Polars and StatsForecast. You must use MSTL decomposition for series with sufficient data and default to 0 for short series to prevent errors and ensure all series are included in the final output.
Communication & Style Preferences
- Use Python code with Polars and StatsForecast libraries.
- Maintain clear variable names for filtering steps (e.g.,
,short_series
).long_series - Ensure the final output is a single Polars DataFrame ready for ensemble modeling.
Operational Rules & Constraints
- Input Data: Assume input is a Polars DataFrame
with columnsdf
,unique_id
, andds
.y - Parameters: Define
(minimum observations required for decomposition) andmin_series_length
(forecast horizon for MSTL).horizon - Dynamic Season Length: Do not hardcode the season length. Calculate the season length dynamically for each series (e.g., using
or a similar heuristic derived from the data length).len(series) // 2 - Filtering:
- Calculate the count of observations per
.unique_id - Split series into
(count <= min_series_length) andshort_series
(count > min_series_length).long_series
- Calculate the count of observations per
- Decomposition (Long Series):
- Filter the original DataFrame to include only
.long_series - Create a
set by grouping byvalid
and taking theunique_id
.tail(horizon) - Create a
set by performing an anti-join withtrain
onvalid
.['unique_id', 'ds'] - Apply
usingmstl_decomposition
with the dynamically calculated season length to obtainMSTL(season_length=...)
.transformed_df
- Filter the original DataFrame to include only
- Imputation (Short Series):
- Join the original DataFrame with the
IDs.short_series - Add a column
populated withseasonal
(zero).0
- Join the original DataFrame with the
- Concatenation:
- Select columns
from both the decomposed long series data and the modified short series data.['unique_id', 'ds', 'y', 'seasonal'] - Concatenate these DataFrames.
- Sort the final result by
.['unique_id', 'ds']
- Select columns
Anti-Patterns
- Do not use
orstatsmodels.tsa.seasonal.STL
; usetsfeatures
for MSTL.StatsForecast - Do not hardcode the
orseason_length
parameter; calculate it dynamically.freq - Do not attempt to decompose series shorter than
as this causes errors.min_series_length - Do not drop short series from the final output; they must be included with 0 seasonality.
Triggers
- extract seasonal features for ensemble model
- handle short time series in mstl decomposition
- dynamic season length stl decomposition
- set seasonality to zero for short series
- mstl decomposition with varying series lengths