Skip to content
Prev 200641 / 398503 Next

SVM Param Tuning with using SNOW package

Hi Charlie,


Yes, you are perfectly right, when I make the clusters I should put 2, not
10 (it remained 10 from previous trials with 10 slaves).

cl<- makeCluster(2, type="SOCK" ) 

To tell the truth I do not understand very well what the 2nd parameter for
clusterApplyLB() has to be.

If the function sv.lin has just 1 parameter, sv.lin(c), where c is the cost,
how should I call clusterApplyLB?


 ? clusterApply LB(cl, ?,sv.lin, c=cost1)  ?



Below, I am providing a working example, using the gasoline data that comes
in the pls package.

Thank you for your time! 


library(e1071)
library(snow)
library(pls)

data(gasoline)

X=gasoline$NIR
Y=gasoline$octane

NR=10
cost1=seq(0.5,30, length=NR)


sv.lin<- function(c) {

for (i in 1:NR) {

ind=sample(1:60,50)
gTest<-  data.frame(Y=I(Y[-ind]),X=I(X[-ind,])) 
gTrain<- data.frame(Y=I(Y[ind]),X=I(X[ind,])) 

svm.lin   	  <- svm(gTrain$X,gTrain$Y, kernel="linear",cost=c[i], cross=5)
results.lin   <- predict(svm.lin, gTest$X)

e.test.lin     <- sqrt(sum((results.lin-gTest$Y)^2)/length(gTest$Y))

return(e.test.lin)
}
}


cl<- makeCluster(2, type="SOCK" ) 


clusterEvalQ(cl,library(e1071))


clusterExport(cl,c("NR","Y","X")) 


RMSEP<-clusterApplyLB(cl,?,sv.lin,c=cost1)

stopCluster(cl)
cls59 wrote: