在进行支持向量机并行计算的时候,在数据量较小的时候可以运行,但数据量大了电脑就要死机、自动重启。请问为何?求解。谢谢!
代码如下:
af =foreach(r = 1:R, .combine = rbind) %do% {
bf = foreach(k = 1:K, .combine = rbind) %do% {
validation.idx = cv$subsets[which(cv$which == k),r]
# 取得训练数据和检验数据
train = d.train[-validation.idx,]
validation = d.train[validation.idx,]
cf = foreach (i = 1:cost.r, .combine = rbind) %do% {
df= foreach (j = 1:gamma.r, .combine = rbind) %do% {
library(snowfall)
library(parallel)
sfInit(parallel = T, cpus = detectCores() - 4)
myfun = function (l) {
library(e1071)
# svm
svm.fit = svm(reac~.,data = train, nu = l,cost = i, gamma = j, kernel="radial",type = "nu-regression" )
svm.pre = ifelse(predict(svm.fit,train[,-9])>mean(predict(svm.fit,train[,-9])),1,0)
reac = as.numeric(train$reac)
n = ifelse(svm.pre == train[,9],1,0)
# result
t = table(pred = svm.pre, true = train[,9])
A = as.vector(t)
ac = (A[1] + A[4])/sum(A[1:4]) # Accuracy
s = A[4]/(A[3]+A[4]) # Sensitive
p = A[4]/(A[2]+A[4]) # precision
f = 2/(1/p+1/s) # F1 score
pe = ((A[4]+A[2])*(A[4]+A[3])+(A[3]+A[1])*(A[2]+A[1]))/(sum(A[1:4])^2) # P(e)
k = (ac-pe)/(1-pe) # Kappa
# output
c(l,ac,s,f,k, sum(n) )
}
sfExport('train','myfun','j','i','K','R')
a = sfLapply(nu.r, myfun)
b = matrix(unlist(a), ncol = 6, byrow = T)
# b
sfStop()
cbind(rep(j, nrow(b)),b)
}
cbind(rep(i,nrow(df)),df)
}
}
}