Learn R Programming

e1071 (version 1.1-2)

svm: Support Vector Machines

Description

svm is used to train a support vector machine. It can be used to carry out general regression and 3 types of classification. At the moment, no more than 2 classes can be classified.

Usage

svm(x, y, svm.type=NULL, kernel.type="radial", degree=3, gamma=1/dim(x)[2],
coef0=0, cost=1, nu=0.5, cachesize=40, tolerance=0.001, epsilon=0.5,
shrinking=TRUE)
summary (svm.obj)

Arguments

x
A data matrix.
y
A response vector with one label for each row of x. Can be either a factor or a numeric vector.
svm.type
svm can either be used as a classification machine or as a regresson machine. Depending of whether y is a factor or not, the default setting for svm.type is C-classification or regression
kernel.type
The kernel used in training and predicting. You might consider changing some of the following parameters, depending on the kernel type. [object Object],[object Object],[object Object],[object Object]
degree
parameter needed for kernel of type polynomial (default: 3)
gamma
parameter needed for all kernels except linear (default: 1/(data dimension))
coef0
parameter needed for kernels of type polynomial and sigmoid (default: 0)
cost
cost of constraints violation. (default: 1)
nu
parameter needed for nu-classification and one-classification
cachesize
cache memory in MB. (default 40)
tolerance
tolerance of termination criterion (default: 0.001)
epsilon
epsilon in the insensitive-loss function (default: 0.5)
shrinking
option whether to use the shrinking-heuristics (default: TRUE)
svm.obj
An object of type svm as returned by svm

Value

  • An object of class svm containing the fitted model, especially:
  • svthe resulting support vectors
  • indexthe index of the resulting support vectors in the data matrix
  • coefsthe corresponding coefficiants
  • (Use summary and print to get some output).

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

predict.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