I applied the SVM algorithm with a Radial kernel to a regression problem using the following packages: caret (train function with SVMRadial method), e1071 (svm function) and kernlab (ksvm function). For functions on caret and kernlab, I fixed the hyperparameter values estimated by svm function from e1071.
I obtained identical results for the svm model from e1071 and ksvm model from kernlab, but for the implementation of the train function on caret the result was completely different.
Here is a reproducible example:
library(caret)
library(kernlab)
library(tidyverse)
library(e1071)
library(hydroGOF)
library(AppliedPredictiveModeling)
#data set
data(solubility)
trainData<-cbind(solTrainY,solTrainXtrans)
names(trainData)[1]<-"Y"
testData<-cbind(solTestY,solTestXtrans)
names(testData)[1]<-"Y_holdout"
#e1071 package
SVMr_e1071 <- svm(Y ~ ., data = trainData, kernel = "radial")
predSVMr_e1071 <- predict(SVMr_e1071, select(testData,-Y_holdout))
modelRMSE1<-rmse(testData$Y_holdout, predSVMr_e1071)
modelRMSE1 #0.6535902
#caret package
SVMrGrid <- expand.grid(.C = 1,.sigma=0.004385965)
SVMr_caret <- train(Y ~ .,
data=trainData,
method = "svmRadial",
tuneGrid = SVMrGrid,
trControl = trainControl(method="none",savePredictions=TRUE))
predSVMr_caret <- predict(SVMr_caret,select(testData,-Y_holdout))
modelRMSE2<-rmse(testData$Y_holdout, predSVMr_caret)
modelRMSE2 #1.887908
#kernlab package
SVMr_k<- ksvm(Y ~ ., data = trainData,kernel ="rbfdot",
C = 1, kpar = list(sigma=0.004385965))
predSVMr_k <- as.numeric(predict(SVMr_k, select(testData,-Y_holdout)))
modelRMSE3<-rmse(testData$Y_holdout, predSVMr_k)
modelRMSE3 #0.6535902
I suspect that in the implementation of the train function, the problem is being considered as classification rather than regression. Is there any way to verify if this is in fact happening? Maybe it is a problem related to my R version (R version 3.3.2 (2016-10-31)?
Any help will be much appreciated.
Best regards, Hellen