Description Usage Arguments Examples
Generic cross-validation for univariate time series
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | crossval_ts(
y,
x = NULL,
fit_func = crossval::fit_lm,
predict_func = crossval::predict_lm,
fcast_func = NULL,
fit_params = NULL,
initial_window = 5,
horizon = 3,
fixed_window = TRUE,
type_forecast = c("mean", "quantiles"),
level = c(80, 95),
seed = 123,
eval_metric = NULL,
cl = NULL,
errorhandling = c("stop", "remove", "pass"),
packages = c("stats", "Rcpp"),
verbose = FALSE,
show_progress = TRUE,
...
)
|
y |
response time series; a vector |
x |
input covariates' matrix (optional) |
fit_func |
a function for fitting the model |
predict_func |
a function for predicting values from the model |
fcast_func |
time series forecasting function |
fit_params |
a list; additional (model-specific) parameters to be passed
to |
initial_window |
an integer; the initial number of consecutive values in each training set sample |
horizon |
an integer; the number of consecutive values in test set sample |
fixed_window |
a boolean; if FALSE, all training samples start at 1 |
type_forecast |
a string; "mean" for mean forecast, "lower", "upper" for lower and upper bounds respectively |
level |
a numeric vector; confidence levels for prediction intervals. |
seed |
random seed for reproducibility of results |
eval_metric |
a function measuring the test errors; if not provided: RMSE for regression and accuracy for classification |
cl |
an integer; the number of clusters for parallel execution |
errorhandling |
specifies how a task evalution error should be handled. If value is "stop", then execution will be stopped if an error occurs. If value is "remove", the result for that task will not be returned. If value is "pass", then the error object generated by task evaluation will be included with the rest of the results. The default value is "stop". |
packages |
character vector of packages that the tasks depend on |
verbose |
logical flag enabling verbose messages. This can be very useful for troubleshooting. |
show_progress |
show evolution of the algorithm |
... |
additional parameters |
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 | require(forecast)
data("AirPassengers")
# Example 1 -----
res <- crossval_ts(y=AirPassengers, initial_window = 10, fcast_func = thetaf)
print(colMeans(res))
# Example 2 -----
fcast_func <- function (y, h, ...)
{
forecast::forecast(forecast::auto.arima(y, ...),
h=h, ...)
}
res <- crossval_ts(y=AirPassengers, initial_window = 10, fcast_func = fcast_func)
print(colMeans(res))
# Example 3 -----
fcast_func <- function (y, h, ...)
{
forecast::forecast(forecast::ets(y, ...),
h=h, ...)
}
res <- crossval_ts(y=AirPassengers, initial_window = 10, fcast_func = fcast_func)
print(colMeans(res))
# Example 4 -----
xreg <- cbind(1, 1:length(AirPassengers))
res <- crossval_ts(y=AirPassengers, x=xreg, fit_func = crossval::fit_lm,
predict_func = crossval::predict_lm,
initial_window = 10,
horizon = 3,
fixed_window = TRUE)
print(colMeans(res))
# Example 5 -----
res <- crossval_ts(y=AirPassengers, x=xreg, fcast_func = thetaf,
initial_window = 10,
horizon = 3,
fixed_window = TRUE, type_forecast="quantiles")
print(colMeans(res))
#' # Example 6 -----
xreg <- cbind(1, 1:length(AirPassengers))
res <- crossval_ts(y=AirPassengers, x=xreg, fit_func = crossval::fit_lm,
predict_func = crossval::predict_lm,
initial_window = 10,
horizon = 3,
fixed_window = TRUE, type_forecast="quantiles")
print(colMeans(res))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.