I am unable to let the ACCURACY function point only to the Validation_set. The code perfectly works only in case the first argument of Accuracy is the whole dataset(“data_tsibble”) but in case I indicate only the validation_set i receive following error message that in English means “the argument must be cohercible to a non-negative integer”:
Messaggi di avvertimento:
1: 2 errors (1 unique) encountered
[2] l'argomento dev'essere coercibile in un intero non-negativo
2: 2 errors (1 unique) encountered
[2] l'argomento dev'essere coercibile in un intero non-negativo
3: 2 errors (1 unique) encountered
[2] l'argomento dev'essere coercibile in un intero non-negativo
4: 2 errors (1 unique) encountered
[2] l'argomento dev'essere coercibile in un intero non-negativo
5: 2 errors (1 unique) encountered
[2] l'argomento dev'essere coercibile in un intero non-negativo
Here follows the full code
# Clear all variables from workspace
rm(list = ls())
# Load required packages
library(fpp3)
library(readxl)
library(tidyverse)
library(fable)
library(fabletools)
library(tsibble)
library(prophet)
library(forecast)
library(urca)
library(distributional)
library(lubridate)
library(writexl)
library(ggplot2)
# Read the dataset
data <- read_excel("D:/TEST.xlsx")
# Convert the data into a tsibble (time series tibble)
data_tsibble <- data |>
mutate(Mesi = yearmonth(Mesi)) |>
as_tsibble(index = Mesi)
# Visualize plot of the original series
data_tsibble |>
autoplot(Intermediato) +
xlab("Mesi") + ylab("Intermediato")
# Create training set and validation set
train_set <- data_tsibble |> filter_index(~ "12/01/2023")
validation_set <- data_tsibble |> filter_index("01/01/2024" ~ .)
fit_models <- train_set |>
model(Ets = ETS(Intermediato),
Arima = ARIMA(Intermediato, stepwise=FALSE, approximation=FALSE),
tslm1 = TSLM(Intermediato ~ trend() + season()),
tslm2 = TSLM(Intermediato ~ trend() + I(trend()^2) + season()),
tslm3 = TSLM(Intermediato ~ trend() + I(trend()^2) + season()))
glance(fit_models) |> arrange(AICc) |> select(.model:BIC)
fc_models <- fit_models |>
forecast(h=nrow(validation_set))
# If the first argument of the function ACCURACY is the whole dataset (data_tsibble), everything works out fine
fc_models |>
accuracy(
data = validation_set,
measures = list(
crps = CRPS,
rmse = RMSE,
mase = MASE,
ss_crps = skill_score(CRPS),
ss_rmse = skill_score(RMSE)
),
n_quantiles = 100
) |>
group_by(.model) %>%
summarise(
ss_crps = mean(ss_crps) * 100,
ss_rmse = mean(ss_rmse) * 100,
mase = mean(mase)
)
# If the first argument of the function ACCURACY is the whole dataset (data_tsibble), everything works out fine
fc_models |>
accuracy(validation_set,
list(rmse=RMSE,
mae=MAE,
mape=MAPE,
mase=MASE,
rmsse=RMSSE,
acf1=ACF1,
crps=CRPS,
skill_crps=skill_score(CRPS),
skill_rmse=skill_score(RMSE)))
How can i solve this problem?
Thanks a lot
Mark