Multiple Seasonal-Trend decomposition with LOESS (MSTL)
Fast, effective forecasting of time series exhibiting multiple seasonality and trend.
Introduction
The MSTL algorithm, introduced in this paper, provides a way of applying Seasonal-Trend decomposition to multiple seasonalities. This allows effective modelling of time series with multiple complex components.
As well as the MSTL algorithm this crate also provides the
[MSTLModel
] struct, which is capable of running the MSTL
algorithm over some time series data, then modelling the
final trend component using a given trend forecaster.
It can then recombine the forecasted trend with the
decomposed seasonalities to generate in-sample and
out-of-sample forecasts.
The latter use case is the main entrypoint of this crate.
Usage
use ;
#
Using alternative trend models
The MSTLModel
is generic over the trend model used. As long
as the model passed implements the TrendModel
trait from this
crate, it can be used to model the trend after decomposition.
For example, the AutoETS
struct from the ets
crate can be
used instead. First, add the augurs_ets
crate to your Cargo.toml
with the mstl
feature enabled:
[]
= { = "*", = ["mstl"] }
use AutoETS;
use MSTLModel;
let y = vec!;
let periods = vec!;
let trend_model = non_seasonal;
let mstl = new;
let fit = mstl.fit?;
let in_sample = fit.predict_in_sample?;
let out_of_sample = fit.predict?;
(Note that the above example doesn't compile for this crate due to a circular dependency, but would work in a separate crate!)
Implementing a trend model
To use your own trend model, you'll need a struct that implements
the TrendModel
trait. See below for an example of a model
that predicts a constant value for all time points in the horizon.
use Cow;
use ;
use ;
// The unfitted model. Sometimes this will need state!
// The fitted model. This will invariable need state.
Credits
This implementation is based heavily on both the R implementation and the statsforecast implementation. It also makes heavy use of the [stlrs][] crate.
References
License
Dual-licensed to be compatible with the Rust project.
Licensed under the Apache License, Version 2.0 <http://www.apache.org/licenses/LICENSE-2.0>
or the MIT license <http://opensource.org/licenses/MIT>
, at your option.