17 releases (5 breaking)

0.7.0 Nov 25, 2024
0.6.3 Nov 20, 2024
0.5.4 Oct 28, 2024
0.4.3 Oct 18, 2024
0.2.0 Jun 5, 2024

#157 in Machine learning

Download history 4/week @ 2024-08-12 1/week @ 2024-09-16 13/week @ 2024-09-23 6/week @ 2024-10-07 734/week @ 2024-10-14 395/week @ 2024-10-21 164/week @ 2024-10-28 320/week @ 2024-11-04 101/week @ 2024-11-11 207/week @ 2024-11-18 171/week @ 2024-11-25

804 downloads per month
Used in augurs

MIT/Apache

48KB
1K SLoC

High level forecasting API for augurs

augurs-forecaster contains a high-level API for training and predicting with time series models. It currently allows you to combine a model with a set of transformations (such as imputation of missing data, min-max scaling, and log/logit transforms) and fit the model on the transformed data, automatically handling back-transformation of forecasts and prediction intervals.

Usage

First add this crate and any required model crates to your Cargo.toml:

[dependencies]
augurs-ets = { version = "*", features = ["mstl"] }
augurs-forecaster = "*"
augurs-mstl = "*"
use augurs::{
    ets::{AutoETS, trend::AutoETSTrendModel},
    forecaster::{Forecaster, Transform, transforms::MinMaxScaleParams},
    mstl::MSTLModel
};

let data = &[
    1.0, 1.2, 1.4, 1.5, f64::NAN, 1.4, 1.2, 1.5, 1.6, 2.0, 1.9, 1.8
];

// Set up the model. We're going to use an MSTL model to handle
// multiple seasonalities, with a non-seasonal `AutoETS` model
// for the trend component.
// We could also use any model that implements `augurs_core::Fit`.
let ets = AutoETS::non_seasonal().into_trend_model();
let mstl = MSTLModel::new(vec![2], ets);

// Set up the transforms.
let transforms = vec![
    Transform::linear_interpolator(),
    Transform::min_max_scaler(MinMaxScaleParams::from_data(data.iter().copied())),
    Transform::log(),
];

// Create a forecaster using the transforms.
let mut forecaster = Forecaster::new(mstl).with_transforms(transforms);

// Fit the forecaster. This will transform the training data by
// running the transforms in order, then fit the MSTL model.
forecaster.fit(&data).expect("model should fit");

// Generate some in-sample predictions with 95% prediction intervals.
// The forecaster will handle back-transforming them onto our original scale.
let in_sample = forecaster
    .predict_in_sample(0.95)
    .expect("in-sample predictions should work");

// Similarly for out-of-sample predictions:
let out_of_sample = forecaster
    .predict(5, 0.95)
    .expect("out-of-sample predictions should work");

Dependencies

~0.7–1.1MB
~25K SLoC