谢谢你的快速回答,我真的很感激。现在我面临另一个问题,我让脚本在晚上通过 nohup 运行,我在日志中发现了以下内容:
[1] "DB PROD Connected"
[1] "DB PROD Connected"
[1] "Getting RAW data"
[1] "Maximum forecasting horizon is 52, fetching weekly data"
[1] "Removing duplicates if we have them"
[1] "Original data has 1860590 rows"
[1] "Data without duplicates has 1837995 rows"
`summarise()` regrouping output by 'A', 'B' (override with `.groups` argument)
[1] "Removing non active customers"
[1] "Data without duplicates and without active customers has 1654483 rows"
0.398 sec elapsed
[1] "Removing customers with last data older than 1.5 years"
[1] "Data without duplicates, customers that are not active and old customers has 1268610 rows"
0.223 sec elapsed
[1] "Augmenting data"
12.103 sec elapsed
[1] "Creating tsibble"
7.185 sec elapsed
[1] "Filling gaps for not breaking groups"
9.568 sec elapsed
[1] "Training theta models for forecasting horizon 52"
[1] "Using 12 sessions from as future::plan()"
Repacking large object
[1] "Training auto_arima models for forecasting horizon 52"
[1] "Using 12 sessions from as future::plan()"
Error: target auto_arima failed.
diagnose(auto_arima)error$message:
object 'ts_models' not found
diagnose(auto_arima)error$calls:
1. └─global::trainModels(...)
In addition: Warning message:
9 errors (2 unique) encountered for theta
[3] function cannot be evaluated at initial parameters
[6] Not enough data to estimate this ETS model.
Execution halted
对象 ts_models 是在我的训练脚本中创建的对象,它基本上是我的函数 trainModels 返回的对象。在我看来,也许输入数据参数是干净的,这就是它失败的原因?
另一个问题由于某种原因,我的模型在训练 thetha 模型后没有保存。有没有办法指定德雷克在计算一个模型的准确性并保存 .qs 文件之前不跳转到下一个模型?
我的训练功能如下:
trainModels <- function(input_data, max_forecast_horizon, model_type, max_multisession_cores) {
options(future.globals.maxSize = 1500000000)
future::plan(multisession, workers = max_multisession_cores) #breaking infrastructure once again ;)
set.seed(666) # reproducibility
if(max_forecast_horizon <= 104) {
print(paste0("Training ", model_type, " models for forecasting horizon ", max_forecast_horizon))
print(paste0("Using ", max_multisession_cores, " sessions from as future::plan()"))
if(model_type == "prophet_multiplicative") {
ts_models <- input_data %>% model(prophet = fable.prophet::prophet(snsr_val_clean ~ season("week", 2, type = "multiplicative") +
season("month", 2, type = "multiplicative")))
} else if(model_type == "prophet_additive") {
ts_models <- input_data %>% model(prophet = fable.prophet::prophet(snsr_val_clean ~ season("week", 2, type = "additive") +
season("month", 2, type = "additive")))
} else if(model_type == "auto.arima") {
ts_models <- input_data %>% model(auto_arima = ARIMA(snsr_val_clean))
} else if(model_type == "arima_with_yearly_fourier_components") {
ts_models <- input_data %>% model(auto_arima_yf = ARIMA(snsr_val_clean ~ fourier("year", K = 2)))
} else if(model_type == "arima_with_monthly_fourier_components") {
ts_models <- input_data %>% model(auto_arima_mf = ARIMA(snsr_val_clean ~ fourier("month", K=2)))
} else if(model_type == "regression_with_arima_errors") {
ts_models <- input_data %>% model(auto_arima_mf_reg = ARIMA(snsr_val_clean ~ month + year + quarter + qday + yday + week))
} else if(model_type == "tslm") {
ts_models <- input_data %>% model(tslm_reg_all = TSLM(snsr_val_clean ~ year + quarter + month + day + qday + yday + week + trend()))
} else if(model_type == "theta") {
ts_models <- input_data %>% model(theta = THETA(snsr_val_clean ~ season()))
} else if(model_type == "ensemble") {
ts_models <- input_data %>% model(ensemble = combination_model(ARIMA(snsr_val_clean),
ARIMA(snsr_val_clean ~ fourier("month", K=2)),
fable.prophet::prophet(snsr_val_clean ~ season("week", 2, type = "multiplicative") +
season("month", 2, type = "multiplicative"),
theta = THETA(snsr_val_clean ~ season()),
tslm_reg_all = TSLM(snsr_val_clean ~ year + quarter + month + day + qday + yday + week + trend())))
)
}
}
else if(max_forecast_horizon > 104) {
print(paste0("Training ", model_type, " models for forecasting horizon ", max_forecast_horizon))
print(paste0("Using ", max_multisession_cores, " sessions from as future::plan()"))
if(model_type == "prophet_multiplicative") {
ts_models <- input_data %>% model(prophet = fable.prophet::prophet(snsr_val_clean ~ season("month", 2, type = "multiplicative") +
season("month", 2, type = "multiplicative")))
} else if(model_type == "prophet_additive") {
ts_models <- input_data %>% model(prophet = fable.prophet::prophet(snsr_val_clean ~ season("month", 2, type = "additive") +
season("year", 2, type = "additive")))
} else if(model_type == "auto.arima") {
ts_models <- input_data %>% model(auto_arima = ARIMA(snsr_val_clean))
} else if(model_type == "arima_with_yearly_fourier_components") {
ts_models <- input_data %>% model(auto_arima_yf = ARIMA(snsr_val_clean ~ fourier("year", K = 2)))
} else if(model_type == "arima_with_monthly_fourier_components") {
ts_models <- input_data %>% model(auto_arima_mf = ARIMA(snsr_val_clean ~ fourier("month", K=2)))
} else if(model_type == "regression_with_arima_errors") {
ts_models <- input_data %>% model(auto_arima_mf_reg = ARIMA(snsr_val_clean ~ month + year + quarter + qday + yday))
} else if(model_type == "tslm") {
ts_models <- input_data %>% model(tslm_reg_all = TSLM(snsr_val_clean ~ year + quarter + month + day + qday + yday + trend()))
} else if(model_type == "theta") {
ts_models <- input_data %>% model(theta = THETA(snsr_val_clean ~ season()))
} else if(model_type == "ensemble") {
ts_models <- input_data %>% model(ensemble = combination_model(ARIMA(snsr_val_clean),
ARIMA(snsr_val_clean ~ fourier("month", K=2)),
fable.prophet::prophet(snsr_val_clean ~ season("month", 2, type = "multiplicative") +
season("year", 2, type = "multiplicative"),
theta = THETA(snsr_val_clean ~ season()),
tslm_reg_all = TSLM(snsr_val_clean ~ year + quarter + month + day + qday +
yday + trend())))
)
}
}
return(ts_models)
}
BR/E