How to use polynomial kernel in SVM using R

svm
r

#1

I am currently studying about SVM in R and while studying that I came across that data can be separated by linear kernel if data is linearly separable and if data is not linearly separable then data can be separated by non-linear kernel like radial and polynomial I am able to use the radial kernel but I am not able to use polynomial kernel.

set.seed(1)
x<-matrix(rnorm(400),ncol=2)
x[1:100,]=x[1:100,]+2
x[100:150,]=x[100:150,]-2
y<-c(rep(1,150),rep(2,50))
dat1<-data.frame(x,as.factor(y))
plot(x,col=y)
train=sample(200,100)
svfit=svm(y~.,data=dat1,kernel=“radial”,gama=1,cost=1)

here I am able to use the radial kernel .How to apply polynomial kernel in this data.


#2

svfit=svm(y~.,data=dat1,kernel=“polynomial”,gama=1,cost=1)

You can edit the parameters degree, gamma and coef0 parameters:
degree: parameter needed for kernel of type polynomial (default: 3)
gamma: parameter needed for all kernels except linear (default: 1/(data dimension))
coef0: parameter needed for kernels of type polynomial and sigmoid (default: 0)

Also see, www.inside-r.org/node/57517