Learn R Programming

e1071 (version 1.1-3)

predict.svm: Predict method for Support Vector Machines

Description

This function predicts values based upon a model trained by svm.

Usage

predict.svm(model, x, type="class")

Arguments

model
object of class svm, created by svm.
x
A matrix containing the input data.
type
If raw is supplied, the estimated values are returned. With class, predict returns the first level of the training response for negative (non-zero) values, and the second level otherwise. If class

Value

  • The predicted value.

References

  • Chang, Chih-Chung and Lin, Chih-Jen: LIBSVM 2.0: Solving Different Support Vector Formulations. http://www.csie.ntu.edu.tw/~cjlin/papers/libsvm2.ps.gz
  • Chang, Chih-Chung and Lin, Chih-Jen: Libsvm: Introduction and Benchmarks http://www.csie.ntu.edu.tw/~cjlin/papers/q2.ps.gz

See Also

svm

Examples

Run this code
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