data(iris)
# amputate data to two factors
iris.sub <- subset(iris, Species != "virginica")
# get independent vars
x <- subset (iris.sub, select = -Species)
# get responses
y <- iris.sub[,"Species"]
# coercion needed for correct factor levels
y <- as.factor(as.character(y))
# default with factor response: classification mode
model <- svm (x, y)
print (model)
summary (model)
# test with train data
pred <- predict (model, x)
# should be TRUE:
all.equal (pred, y)
# try regression mode on two dimensions in linear mode
model <- svm (x[,"Petal.Length"], x[,"Petal.Width"],
svm.type="regression", kernel.type="linear")
print (model)
pred <- predict (model,x[,"Petal.Length"])
par (mfcol=c(1,2))
plot(x[,"Petal.Length"],x[,"Petal.Width"])
plot(x[,"Petal.Length"],pred)
Run the code above in your browser using DataLab