1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! Time series forecasting that picks its model by what would have worked.
//!
//! `foresight` fits several models to a series, replays the past to see how
//! each would have done (rolling-origin backtest), chooses by out-of-sample
//! error and reports intervals taken from the errors actually observed —
//! including intervals for the total of the next k periods. It has no
//! dependencies and every result is deterministic.
//!
//! ```
//! use foresight::{models, Backtest, Series};
//!
//! // eight years of monthly data starting in January
//! let sales: Vec<f64> = (0..96)
//! .map(|t| 100.0 * 1.004f64.powi(t) * [1.1, 0.8, 0.9, 1.0, 1.0, 0.9, 1.0, 1.0, 0.9, 1.0, 1.1, 1.3][t as usize % 12])
//! .collect();
//! let y = Series::monthly(&sales, 0);
//!
//! let report = Backtest::default().run(y, &models::defaults()).unwrap();
//! let best = report.chosen();
//! println!("{} (MAPE {:.1}%)", best.name, best.score);
//! for p in &best.forecast {
//! let i = p.interval(0.80).unwrap();
//! println!("h={:2} {:8.1} [{:8.1}, {:8.1}]", p.horizon, p.mean, i.lower, i.upper);
//! }
//! // total of the next six months, with its own interval
//! let half_year = best.cumulative(6).unwrap();
//! assert!(half_year.mean > 0.0);
//! ```
//!
//! A single model can be used on its own through the [`Model`] trait:
//!
//! ```
//! use foresight::{models::Theta, Model, Series};
//!
//! let y = [12.0, 14.0, 13.0, 15.0, 17.0, 16.0, 18.0, 20.0];
//! let fit = Theta.fit(Series::non_seasonal(&y)).unwrap();
//! assert_eq!(fit.forecast(3).len(), 3);
//! ```
pub use ;
pub use ;
pub use Regressors;
pub use Series;
pub use ;
/// Version of this crate, to be recorded next to stored forecasts.
pub const VERSION: &str = env!;