Simple moving average. The forecast is the mean of the last order observations.
If order is NULL (the default), the optimal window is selected automatically
according to the chosen information criterion ic.
Calls smooth::sma() from package smooth.
Dictionary
This mlr3::Learner can be instantiated via the dictionary mlr3::mlr_learners or with the associated sugar function mlr3::lrn():
Meta Information
Task type: “fcst”
Predict Types: “response”
Feature Types: “logical”, “integer”, “numeric”, “character”, “factor”, “ordered”, “POSIXct”, “Date”
Required Packages: mlr3, mlr3forecast, smooth
Parameters
| Id | Type | Default | Levels | Range |
| order | integer | NULL | \([1, \infty)\) | |
| ic | character | AICc | AICc, AIC, BIC, BICc | - |
| holdout | logical | FALSE | TRUE, FALSE | - |
| silent | logical | TRUE | TRUE, FALSE | - |
| fast | logical | TRUE | TRUE, FALSE | - |
References
Svetunkov I (2023). “Smooth forecasting with the smooth package in R.” 2301.01790, https://arxiv.org/abs/2301.01790.
See also
Chapter in the mlr3book: https://mlr3book.mlr-org.com/chapters/chapter2/data_and_basic_modeling.html#sec-learners
Package mlr3learners for a solid collection of essential learners.
Package mlr3extralearners for more learners.
as.data.table(mlr_learners)for a table of available Learners in the running session (depending on the loaded packages).mlr3pipelines to combine learners with pre- and postprocessing steps.
Package mlr3viz for some generic visualizations.
Extension packages for additional task types:
mlr3proba for probabilistic supervised regression and survival analysis.
mlr3cluster for unsupervised clustering.
mlr3tuning for tuning of hyperparameters, mlr3tuningspaces for established default tuning spaces.
Other Learner:
LearnerFcst,
mlr_learners_fcst.adam,
mlr_learners_fcst.arfima,
mlr_learners_fcst.arima,
mlr_learners_fcst.auto_adam,
mlr_learners_fcst.auto_arima,
mlr_learners_fcst.auto_ces,
mlr_learners_fcst.auto_gum,
mlr_learners_fcst.auto_msarima,
mlr_learners_fcst.bagged,
mlr_learners_fcst.bats,
mlr_learners_fcst.ces,
mlr_learners_fcst.croston,
mlr_learners_fcst.ets,
mlr_learners_fcst.gum,
mlr_learners_fcst.holt_winters,
mlr_learners_fcst.mean,
mlr_learners_fcst.msarima,
mlr_learners_fcst.nnetar,
mlr_learners_fcst.prophet,
mlr_learners_fcst.random_walk,
mlr_learners_fcst.spline,
mlr_learners_fcst.stlm,
mlr_learners_fcst.struct_ts,
mlr_learners_fcst.tbats,
mlr_learners_fcst.theta,
mlr_learners_fcst.tscount,
mlr_learners_fcst.tslm
Super classes
mlr3::Learner -> mlr3::LearnerRegr -> LearnerFcst -> LearnerFcstSma
Methods
Inherited methods
mlr3::Learner$base_learner()mlr3::Learner$configure()mlr3::Learner$encapsulate()mlr3::Learner$format()mlr3::Learner$help()mlr3::Learner$predict()mlr3::Learner$predict_newdata()mlr3::Learner$print()mlr3::Learner$reset()mlr3::Learner$selected_features()mlr3::Learner$train()mlr3::LearnerRegr$predict_newdata_fast()
Examples
# Define the Learner and set parameter values
learner = lrn("fcst.sma")
print(learner)
#>
#> ── <LearnerFcstSma> (fcst.sma): Simple Moving Average ──────────────────────────
#> • Model: -
#> • Parameters: list()
#> • Packages: mlr3, mlr3forecast, and smooth
#> • Predict Types: [response]
#> • Feature Types: logical, integer, numeric, character, factor, ordered,
#> POSIXct, and Date
#> • Encapsulation: none (fallback: -)
#> • Properties: featureless and missings
#> • Other settings: use_weights = 'error', predict_raw = 'FALSE'
# Define a Task
task = tsk("airpassengers")
# Create train and test set
ids = partition(task)
# Train the learner on the training ids
learner$train(task, row_ids = ids$train)
# Print the model
print(learner$model)
#> Time elapsed: 0.02 seconds
#> Model estimated using sma() function: SMA(1)
#> With backcasting initialisation
#> Distribution assumed in the model: Normal
#> Loss function type: MSE; Loss function value: 538.7708
#> ARMA parameters of the model:
#> Lag 1
#> AR(1) 1
#>
#> Sample size: 96
#> Number of estimated parameters: 1
#> Number of degrees of freedom: 95
#> Number of provided parameters: 1
#> Information criteria:
#> AIC AICc BIC BICc
#> 878.2081 878.2506 880.7724 880.8695
# Importance method
if ("importance" %in% learner$properties) print(learner$importance())
# Make predictions for the test rows
predictions = learner$predict(task, row_ids = ids$test)
# Score the predictions
predictions$score()
#> regr.mse
#> 17585.4