svm: Create SVM object

Description Usage Arguments Value Examples

Description

Create and train SVM model object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
SVM(x, ...)

## S3 method for class 'formula'
SVM(formula, data, ...)

## Default S3 method:
SVM(x, y, core = "libsvm", kernel = "linear",
  prep = "none", transductive.learning = FALSE,
  transductive.posratio = -1, C = 1, gamma = if (is.vector(x)) 1 else
  1/ncol(x), coef0 = 0, degree = 3, class.weights = NULL,
  example.weights = NULL, cache_size = 100, tol = 0.001, max.iter = -1,
  verbosity = 4, class.type = "one.versus.all", svm.options = "", ...)

Arguments

x

Training data without labels in one of the following formats: data.frame, data.matrix, SparseM::matrix.csr, Matrix::Matrix, slam::simple_triplet_matrix

...

other arguments not used by this method.

formula

Can be passed with data instead of x, y pair, formula needs to point to lables column, for example: target~.

data

Can be passed instead of x, y pair with formula to mark the labels column, supported formats are: data.frame, data.matrix

y

Labels in one of the followinf formts: factor, vector. Recommended type is factor

core

Support Vector Machine library to use in traning, available are: 'libsvm', 'svmlight'; default: 'libsvm'

kernel

Kernel type as string, available are: 'linear', 'poly', 'rbf', 'sigmoid'; default: 'linear'

  • linear: x'*w

  • poly: (gamma*x'*w + coef0)^{degree}

  • rbf: exp(-gamma*|x-w|^2)

  • sigmoid: tanh(gamma*x'*w + coef0)

prep

Preprocess method as string, available are: 'none', '2e'; default: 'none'. For more information on 2eSVM see: http://www.sciencedirect.com/science/article/pii/S0957417414004138

transductive.learning

Option got SVM model to deduce missing labels from the dataset, default: FALSE NOTE: this feature is only available with svmlight library, missing labels are marked as 'TR', if none are found and transductive to TRUE, label 0 will be interpreted as missing

transductive.posratio

Fraction of unlabeled examples to be classified into the positive class as float from [0,1], default: the ratio of positive and negative examples in the training data

C

Cost/complexity parameter, default: 1

gamma

Parameter for poly, rbf and sigmoid kernels, default: 1/n_features

coef0

For poly and sigmoid kernels, default: 0

degree

For poly kernel, default: 3

class.weights

Named vector with weight fir each class, default: NULL

example.weights

Vector of the same length as training data with weights for each traning example, default: NULL NOTE: this feature is only supported with svmlight library

cache_size

Cache memory size in MB, default: 100

tol

Tolerance of termination criterion, default: 1e-3

max.iter

Depending on library:

  • libsvm: number of iterations after which the training porcess is killed (it can end earlier is desired tolerance is met), default: 1e6

  • svmlight: number of iterations after which if there is no progress traning is killed, default: -1 (no limit)

verbosity

How verbose should the process be, as integer from [1,6], default: 4

class.type

Multiclass algorithm type as string, available are: 'one.versus.all', 'one.versus.one'; default: 'one.versus.one'

svm.options

enables to pass all svmlight command lines arguments for more advanced options, for details see http://svmlight.joachims.org/

Value

SVM model object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## Not run: 
# train SVM from data in x and labels in y
svm <- SVM(x, y, core="libsvm", kernel="linear", C=1)

# train SVM using a dataset with both data and lables and a formula pointing to labels
formula <- target ~ .
svm <- SVM(formula, data, core="svmlight", kernel="rbf", gamma=1e3)

# train a model with 2eSVM algorithm
data(svm_breast_cancer_dataset)
ds <- svm.breastcancer.dataset
svm.2e <- SVM(x=ds[,-1], y=ds[,1], core="libsvm", kernel="linear", prep = "2e", C=10);
# more at \url{http://r.gmum.net/samples/svm.2e.html}

# train SVM on a multiclass data set
data(iris)
# with "one vs rest" strategy
svm.ova <- SVM(Species ~ ., data=iris, class.type="one.versus.all", verbosity=0)
# or with "one vs one" strategy
svm.ovo <- SVM(x=iris[,1:4], y=iris[,5], class.type="one.versus.one", verbosity=0)

# we can use svmlights sample weighting feature, suppose we have weights vector
# with a weight for every sample in the traning data
weighted.svm <- SVM(formula=y~., data=df, core="svmlight", kernel="rbf", C=1.0,
                    gamma=0.5, example.weights=weights)

# svmlight alows us to determine missing labels from a dataset
# suppose we have a labels y with missing labels marked as zeros
svm.transduction <- SVM(x, y, transductive.learning=TRUE, core="svmlight")

# for more in-depth examples visit \url{http://r.gmum.net/getting_started.html}

## End(Not run)

gmum.r documentation built on May 29, 2017, 3:52 p.m.

Related to svm in gmum.r...