I am trying to create a 2D plot using SVM in library(kernlab), but it appears the plot function is only appropriate for binary classification. I would like to be able to plot 3 (or more) groups, as in the example below.
My data is structured just like the iris data, so I will use it to illustrate.
After fitting the model:
fit.ksvm <- ksvm(Species~., data=iris, kernel= "rbfdot", prob.model=TRUE)
fit.ksvm
I use the plot function for ksvm:
plot(fit.ksvm, data=iris)
and get the message following:
> plot(fit.ksvm, data=iris)
Error in .local(x, ...) :
plot function only supports binary classification
When I try similar analyses using a two-way classification, the plot is produced. So, I think the issue is multiple groups. Can anyone think of a way to create a two-dimensional "heat-map" similar to the one below, but using an SVM classification model with three (or more?) classes?
two-way SVM classification
x <- rbind(matrix(rnorm(120),,2),matrix(rnorm(120,mean=3),,2))
y <- matrix(c(rep(1,60),rep(-1,60)))
svp <- ksvm(x,y,type="C-svc")
plot(svp,data=x)
You could use the e1071 library
library(e1071)
m <- svm(Species~., data = iris)
plot(m, iris, Petal.Width ~ Petal.Length, slice = list(Sepal.Width = 3, Sepal.Length = 4))