使用 Arima 预测可能不起作用
Using Arima forecast with possibly doesn't work
我有两段代码:
一个在工作,另一个没有。
也许有人知道为什么它不起作用。
PS。我知道这不是完全可重现的示例,但如果有必要,我会提供一个。
arima_cv = forecast_data_ini_split %>%
unnest(training_splits_for_cv_models) %>%
crossing(arima_models_for_cv %>% slice(17:18)) %>%
mutate(analysis_data = map(.x = splits, ~tk_analysis_fun(.x))) %>%
mutate(assessment_data = map(.x = splits, ~tk_assessment_fun(.x)))
这个有效
good = arima_cv %>%
mutate(models = furrr::future_pmap(list(analysis_data, p, d, q, P, D, Q),
.f = ~Arima(y = ..1, order = c(..2, ..3, ..4), seasonal = c(..5, ..6, ..7), xreg = NULL,
include.mean = TRUE, include.drift = FALSE, method ="CSS-ML"))) %>%
mutate(models_metrics_ass = map2(.x = models, .y = assessment_data, ~accuracy_assessment_fun(.x, .y)))
这个没有
bad = arima_cv %>%
mutate(models = pmap(list(analysis_data, p, d, q, P, D, Q),
~possibly(Arima, otherwise = NULL )(y = ..1, order = c(..2, ..3, ..4), seasonal = c(..5, ..6, ..7), xreg = NULL,
include.mean = TRUE, include.drift = FALSE, method ="ML"))) %>%
mutate(models_metrics_ass = map2(.x = models, .y = assessment_data, ~accuracy_assessment_fun(.x, .y)))
错误信息是:
Error in eval(expr, p) : the ... list contains fewer than 4 elements
最后一行代码有问题:
mutate(models_metrics_ass = map2(.x = models, .y = assessment_data, ~accuracy_assessment_fun(.x, .y)))
似乎可能以某种方式改变了模型的输出,我无法做出准确的预测和计数。
提前致谢,
塞维
所以,
问题是 Arima,而不是 possibly。
我在 include.drift 参数中放置了一个常量,而它应该是一个变量。
顺便提一句。 possible 和 pmap 的例子很少,所以如果你想要和工作的例子,请写信给我。
unnest(training_splits_for_cv_models) %>%
left_join(arima_models_for_cv) %>%
# crossing(arima_models_for_cv %>%
# slice(17:19) %>%
mutate(analysis_data = map(.x = splits, ~tk_analysis_fun(.x))) %>%
mutate(assessment_data = map(.x = splits, ~tk_assessment_fun(.x))) %>%
mutate(models = furrr::future_pmap(list(analysis_data, p, d, q, P, D, Q, include.drift),
.f = ~possibly(Arima, otherwise = NULL)(y = ..1,
order = c(..2, ..3, ..4),
seasonal = c(..5, ..6, ..7),
include.drift = ..8, method ="CSS-ML"))) %>%
mutate(models_metrics_ass = map2(.x = models, .y = assessment_data, ~accuracy_assessment_fun(.x, .y)))
我有两段代码: 一个在工作,另一个没有。 也许有人知道为什么它不起作用。
PS。我知道这不是完全可重现的示例,但如果有必要,我会提供一个。
arima_cv = forecast_data_ini_split %>%
unnest(training_splits_for_cv_models) %>%
crossing(arima_models_for_cv %>% slice(17:18)) %>%
mutate(analysis_data = map(.x = splits, ~tk_analysis_fun(.x))) %>%
mutate(assessment_data = map(.x = splits, ~tk_assessment_fun(.x)))
这个有效
good = arima_cv %>%
mutate(models = furrr::future_pmap(list(analysis_data, p, d, q, P, D, Q),
.f = ~Arima(y = ..1, order = c(..2, ..3, ..4), seasonal = c(..5, ..6, ..7), xreg = NULL,
include.mean = TRUE, include.drift = FALSE, method ="CSS-ML"))) %>%
mutate(models_metrics_ass = map2(.x = models, .y = assessment_data, ~accuracy_assessment_fun(.x, .y)))
这个没有
bad = arima_cv %>%
mutate(models = pmap(list(analysis_data, p, d, q, P, D, Q),
~possibly(Arima, otherwise = NULL )(y = ..1, order = c(..2, ..3, ..4), seasonal = c(..5, ..6, ..7), xreg = NULL,
include.mean = TRUE, include.drift = FALSE, method ="ML"))) %>%
mutate(models_metrics_ass = map2(.x = models, .y = assessment_data, ~accuracy_assessment_fun(.x, .y)))
错误信息是:
Error in eval(expr, p) : the ... list contains fewer than 4 elements
最后一行代码有问题:
mutate(models_metrics_ass = map2(.x = models, .y = assessment_data, ~accuracy_assessment_fun(.x, .y)))
似乎可能以某种方式改变了模型的输出,我无法做出准确的预测和计数。
提前致谢, 塞维
所以,
问题是 Arima,而不是 possibly。
我在 include.drift 参数中放置了一个常量,而它应该是一个变量。
顺便提一句。 possible 和 pmap 的例子很少,所以如果你想要和工作的例子,请写信给我。
unnest(training_splits_for_cv_models) %>%
left_join(arima_models_for_cv) %>%
# crossing(arima_models_for_cv %>%
# slice(17:19) %>%
mutate(analysis_data = map(.x = splits, ~tk_analysis_fun(.x))) %>%
mutate(assessment_data = map(.x = splits, ~tk_assessment_fun(.x))) %>%
mutate(models = furrr::future_pmap(list(analysis_data, p, d, q, P, D, Q, include.drift),
.f = ~possibly(Arima, otherwise = NULL)(y = ..1,
order = c(..2, ..3, ..4),
seasonal = c(..5, ..6, ..7),
include.drift = ..8, method ="CSS-ML"))) %>%
mutate(models_metrics_ass = map2(.x = models, .y = assessment_data, ~accuracy_assessment_fun(.x, .y)))