pca – Principal component analysis – linear factor extraction.#
Back to op axis | Back to L3 | Browse all options
Operational op under axis
op, sub-layerL3_A_step_op, layerl3. Standalone callable:mf.functions.pca_transform.
Function signature#
mf.functions.pca_transform(
panel: pd.DataFrame,
n_components: int | str,
) -> pd.DataFrame
Parameters#
name |
type |
default |
constraint |
description |
|---|---|---|---|---|
|
|
— |
— |
Input panel. Each column is a variable; rows are time periods. Series is promoted to a single-column DataFrame internally. |
|
`int |
str` |
|
>= 1 or ‘all’ |
Returns#
pd.DataFrame — scalar result.
Behavior#
Eigendecomposition of the column covariance; returns the top params.n_components principal components. Implements the Stock-Watson (2002) diffusion-index workflow used throughout FRED-MD applications.
Combine with factor_augmented_ar or factor_augmented_var at L4 to build the diffusion-index forecaster. temporal_rule controls whether components are re-fit per origin (default: expanding_window_per_origin).
When to use
Reducing FRED-MD’s 100+ predictors to a handful of latent factors; factor-augmented forecasts.
In recipe context#
Set params.op = "pca" in the relevant layer to activate this op within a recipe:
# Layer L3 recipe fragment
params:
op: pca
References#
macroforecast design Part 2, L3: ‘feature engineering is a DAG of typed transforms; cascade-depth bounds the longest chain at cascade_max_depth.’
Stock & Watson (2002) ‘Forecasting Using Principal Components from a Large Number of Predictors’, JASA 97(460): 1167-1179.