How to Plot a Classification Graph of a Svm in R

How do I plot a classification graph of a SVM in R

First of all, the plot.svm function assumes that the data varies across two dimensions. The data you have used in your example is only one-dimensional and so the decision boundary would have to be plotted on a line, which isn't supported. Secondly, the function seems to need a data frame as input and you are working with vectors.

This should work...

library(e1071)

day = c(0,1,2,3,4,5,6)
weather = c(1,0,0,0,0,0,0)
happy = factor(c(T,F,F,F,F,F,F))

d = data.frame(day=day, weather=weather, happy=happy)
model = svm(happy ~ day + weather, data = d)
plot(model, d)

SVM Classification Plot in R

Simply change the kernel used to train your model from (probably currently used) rbf to linear. Depending on the library used this parameter might be passed in a different way, but ultimatively this is all you need.

Error in plotting SVM classification graph

Without being sure what exactly causes the problem, I would try to transform the Class column to a factor (so defining the type as C-classification will no longer be necessary) using something like this:

data$Class <- as.factor(data$Class)

or in one step:

model <- svm(as.factor(Class)~.,data, kernel = "linear")


Related Topics



Leave a reply



Submit