# Generating features

Leverage StatsForecast models to create features

Some models create internal representations of the series that can be
useful for other models to use as inputs. One example is the
`MSTL`

model, which decomposes the series into trend and seasonal components.
This guide shows you how to use the
`mstl_decomposition`

function to extract those features for training and then use their
future values for inference.

unique_id | ds | y | |
---|---|---|---|

0 | H1 | 1 | 605.0 |

1 | H1 | 2 | 586.0 |

2 | H1 | 3 | 586.0 |

3 | H1 | 4 | 559.0 |

4 | H1 | 5 | 511.0 |

Suppose that you want to use an ARIMA model to forecast your series but you want to incorporate the trend and seasonal components from the MSTL model as external regressors. You can define the MSTL model to use and then provide it to the mstl_decomposition function.

This generates the dataframe that we should use for training (with the trend and seasonal columns added), as well as the dataframe we should use to forecast.

unique_id | ds | y | trend | seasonal | |
---|---|---|---|---|---|

0 | H1 | 1 | 605.0 | 501.350550 | 124.683643 |

1 | H1 | 2 | 586.0 | 506.424549 | 87.115039 |

2 | H1 | 3 | 586.0 | 511.453736 | 79.479564 |

3 | H1 | 4 | 559.0 | 516.434474 | 45.616992 |

4 | H1 | 5 | 511.0 | 521.362991 | -10.940498 |

unique_id | ds | trend | seasonal | |
---|---|---|---|---|

0 | H1 | 701 | 626.519191 | -22.738998 |

1 | H1 | 702 | 627.423191 | -108.992314 |

2 | H1 | 703 | 628.146391 | -148.675478 |

3 | H1 | 704 | 628.724951 | -183.715284 |

4 | H1 | 705 | 629.187799 | -208.038694 |

We can now train our ARIMA models and compute our forecasts.

unique_id | ds | ARIMA | |
---|---|---|---|

0 | H1 | 701 | 597.716125 |

1 | H1 | 702 | 513.244507 |

2 | H1 | 703 | 475.042450 |

3 | H1 | 704 | 441.217743 |

4 | H1 | 705 | 417.895813 |

We can now evaluate the performance.

And compare this with just using the series values.