并行训练多个 Auto.Arima 个模型
Training Multiple Auto.Arima Models in Parallel
在下面的代码中,我尝试在不同的内核上同时并行训练两个不同的 auto.arima 模型。当我尝试 运行 代码时出现以下错误。我不确定我的问题是 do.call 还是 parLapply,而且我对并行处理还很陌生,所以任何提示都非常有帮助。
Code:
library("forecast")
library("parallel")
TList2<-list(x=tsd1, lambda = Tlambda, stepwise=TRUE, approximation = TRUE)
DList2<-list(x=tsd2, lambda = Rlambda, stepwise=TRUE, approximation = TRUE)
##Parallelizing ARIMA Model Training
# Calculate the number of cores
no_cores <- 1
# Initiate cluster
cl <- makeCluster(no_cores)
ARIMA_List<-list(TList2,DList2)
ARIMA_Models<-parLapply(cl, ARIMA_List,
function(x){do.call(auto.arima, args=x)})
stopCluster(cl)
Error:
Error in checkForRemoteErrors(val) :
one node produced an error: object 'auto.arima' not found
Data:
dput(TList2)
structure(list(x = c(6, 15.5, 22, 16, NA, NA, 13, 13.5, 10, 6,
14.5, 16, NA, 8, 11, NA, 2, 2, 10, NA, 9, NA, 11, 16, NA, 4,
17, 7, 11.5, 22, 20.5, 10, 22, NA, 13, 17, 22, 9, 13, 19, 8,
16, 18, 22, 21, 14, 7, 20, 21.5, 17), lambda = 0.999958829041611,
stepwise = TRUE, approximation = TRUE), .Names = c("x", "lambda",
"stepwise", "approximation"))
dput(DList2)
structure(list(x = c(11, 4, 8, 11, 11, NA, 3, 2.5, 6, 11, 7,
1, NA, 6, 6, NA, 6, 11, 3, NA, 11, NA, 10, 10, NA, NA, 9, 3,
3, 11, 8, 10, NA, NA, 11, 10, 9, 3, 7, NA, 2, 4, 11, 2.5, 3,
NA, 4, 7, 1, 5), lambda = 0.170065851742339, stepwise = TRUE,
approximation = TRUE), .Names = c("x", "lambda", "stepwise",
"approximation"))
我认为 forecast::auto.arima
也应该在集群上可用,所以尝试像这样使用 clusterEvalQ
:
TList2 <- structure(list(x = c(6, 15.5, 22, 16, NA, NA, 13, 13.5, 10, 6,
14.5, 16, NA, 8, 11, NA, 2, 2, 10, NA, 9, NA, 11, 16, NA, 4,
17, 7, 11.5, 22, 20.5, 10, 22, NA, 13, 17, 22, 9, 13, 19, 8,
16, 18, 22, 21, 14, 7, 20, 21.5, 17), lambda = 0.999958829041611,
stepwise = TRUE, approximation = TRUE), .Names = c("x", "lambda",
"stepwise", "approximation"))
DList2<- structure(list(x = c(11, 4, 8, 11, 11, NA, 3, 2.5, 6, 11, 7,
1, NA, 6, 6, NA, 6, 11, 3, NA, 11, NA, 10, 10, NA, NA, 9, 3,
3, 11, 8, 10, NA, NA, 11, 10, 9, 3, 7, NA, 2, 4, 11, 2.5, 3,
NA, 4, 7, 1, 5), lambda = 0.170065851742339, stepwise = TRUE,
approximation = TRUE), .Names = c("x", "lambda", "stepwise",
"approximation"))
library("forecast")
library("parallel")
cl <- makeCluster(no_cores)
clusterEvalQ(cl, library(forecast))
ARIMA_List<-list(TList2,DList2)
ARIMA_Models<-parLapply(cl, ARIMA_List,
function(x){do.call(auto.arima, args=x)})
stopCluster(cl)
在下面的代码中,我尝试在不同的内核上同时并行训练两个不同的 auto.arima 模型。当我尝试 运行 代码时出现以下错误。我不确定我的问题是 do.call 还是 parLapply,而且我对并行处理还很陌生,所以任何提示都非常有帮助。
Code:
library("forecast")
library("parallel")
TList2<-list(x=tsd1, lambda = Tlambda, stepwise=TRUE, approximation = TRUE)
DList2<-list(x=tsd2, lambda = Rlambda, stepwise=TRUE, approximation = TRUE)
##Parallelizing ARIMA Model Training
# Calculate the number of cores
no_cores <- 1
# Initiate cluster
cl <- makeCluster(no_cores)
ARIMA_List<-list(TList2,DList2)
ARIMA_Models<-parLapply(cl, ARIMA_List,
function(x){do.call(auto.arima, args=x)})
stopCluster(cl)
Error:
Error in checkForRemoteErrors(val) :
one node produced an error: object 'auto.arima' not found
Data:
dput(TList2)
structure(list(x = c(6, 15.5, 22, 16, NA, NA, 13, 13.5, 10, 6,
14.5, 16, NA, 8, 11, NA, 2, 2, 10, NA, 9, NA, 11, 16, NA, 4,
17, 7, 11.5, 22, 20.5, 10, 22, NA, 13, 17, 22, 9, 13, 19, 8,
16, 18, 22, 21, 14, 7, 20, 21.5, 17), lambda = 0.999958829041611,
stepwise = TRUE, approximation = TRUE), .Names = c("x", "lambda",
"stepwise", "approximation"))
dput(DList2)
structure(list(x = c(11, 4, 8, 11, 11, NA, 3, 2.5, 6, 11, 7,
1, NA, 6, 6, NA, 6, 11, 3, NA, 11, NA, 10, 10, NA, NA, 9, 3,
3, 11, 8, 10, NA, NA, 11, 10, 9, 3, 7, NA, 2, 4, 11, 2.5, 3,
NA, 4, 7, 1, 5), lambda = 0.170065851742339, stepwise = TRUE,
approximation = TRUE), .Names = c("x", "lambda", "stepwise",
"approximation"))
我认为 forecast::auto.arima
也应该在集群上可用,所以尝试像这样使用 clusterEvalQ
:
TList2 <- structure(list(x = c(6, 15.5, 22, 16, NA, NA, 13, 13.5, 10, 6,
14.5, 16, NA, 8, 11, NA, 2, 2, 10, NA, 9, NA, 11, 16, NA, 4,
17, 7, 11.5, 22, 20.5, 10, 22, NA, 13, 17, 22, 9, 13, 19, 8,
16, 18, 22, 21, 14, 7, 20, 21.5, 17), lambda = 0.999958829041611,
stepwise = TRUE, approximation = TRUE), .Names = c("x", "lambda",
"stepwise", "approximation"))
DList2<- structure(list(x = c(11, 4, 8, 11, 11, NA, 3, 2.5, 6, 11, 7,
1, NA, 6, 6, NA, 6, 11, 3, NA, 11, NA, 10, 10, NA, NA, 9, 3,
3, 11, 8, 10, NA, NA, 11, 10, 9, 3, 7, NA, 2, 4, 11, 2.5, 3,
NA, 4, 7, 1, 5), lambda = 0.170065851742339, stepwise = TRUE,
approximation = TRUE), .Names = c("x", "lambda", "stepwise",
"approximation"))
library("forecast")
library("parallel")
cl <- makeCluster(no_cores)
clusterEvalQ(cl, library(forecast))
ARIMA_List<-list(TList2,DList2)
ARIMA_Models<-parLapply(cl, ARIMA_List,
function(x){do.call(auto.arima, args=x)})
stopCluster(cl)