How to get the linear line in SVM using R

svm
r

#1

I am currently doing a problem on SVM in R and while doing a problem I have created the model and I have also select the kernel equal to linear but I am not getting the complete straight line.I am not able to understand why.

set.seed(1)
x<-matrix(rnorm(20*2),ncol=2) #data
y<-c(rep(-1,10),rep(1,10))#categorical
x[y==1,]=x[y==1,]+1
dat<-data.frame(x=x,y=as.factor(y))# data frame
require(e1071)
svmfit=svm(y~.,data=dat,kernel=“linear”,cost=10,scale=FALSE) #svm model
plot(svmfit,dat)

as it clear I am not getting complete straight line


#2

@hinduja1234 - when you select the kernel as a straight line it tries to fit the best possible straight line this the reason that it some time a straight line is distorted similar to above case .So your model is correct.

Hope this helps!
Regards,
harry