#时间序列 #分析 #预测 #数据分析 #异常检测

augurs-forecaster

为augurs预测库提供高级API

3个不稳定版本

0.3.1 2024年7月30日
0.3.0 2024年7月30日
0.2.0 2024年6月5日

#7 in #预测

Download history 164/week @ 2024-06-02 15/week @ 2024-06-09 5/week @ 2024-06-16 247/week @ 2024-07-28 4/week @ 2024-08-04 4/week @ 2024-08-11

每月 255 次下载

MIT/Apache

45KB
977

为augurs时间序列库提供高级预测API

augurs-forecaster 包含用于训练和预测时间序列模型的高级API。它目前允许您将模型与一组转换(如缺失数据填充、min-max缩放和log/logit转换)组合,并在转换后的数据上拟合模型,自动处理预测和预测区间的反向转换。

用法

首先将此crate,augurs-core,以及任何必需的模型crate添加到您的 Cargo.toml

[dependencies]
augurs-ets = { version = "*", features = ["mstl"] }
augurs-forecaster = "*"
augurs-mstl = "*"
use augurs_ets::{AutoETS, trend::AutoETSTrendModel};
use augurs_forecaster::{Forecaster, Transform, transforms::MinMaxScaleParams};
use augurs_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");

依赖项

~0.7–1.2MB
~27K SLoC