Last data update: 2014.03.03

R: Support Vector Machines
svmEEGR Documentation

Support Vector Machines

Description

svmEEG is used to train a support vector machine classifier of the features selected by the function FeatureEEG. Internally, this function uses the svm function available in the e1071 package. Thus, it is recommended to understand the svm function before using svmEEG.

Usage

svmEEG(x, method = "C-classification", scale = TRUE, kernel = "radial", 
degree = 3, gamma = if (is.vector(x)) 1 else 1/ncol(x), coef0 = 0, 
cost = 1, nu = 0.5, class.weights = NULL, cachesize = 40, tolerance = 0.001, 
epsilon = 0.1, shrinking = TRUE, cross = 0, probability = TRUE, 
fitted = TRUE, seed = 1L, subset, na.action = na.omit)

Arguments

x

the features to be classified. Must be a list of class featureEEG produced by the function FeatureEEG.

method

the method to be used in svm. It has to be a classification machine.

scale

a logical vector indicating the variables to be scaled. If scale is of length 1, the value is recycled as many times as needed. Per default, data are scaled internally to zero mean and unit variance. The center and scale values are returned and used for later predictions. See svm for more details.

kernel

the kernel used in training and predicting. One of: linear, polynomial, radial basis or sigmoid. See svm for more details.

degree

parameter needed for kernel of type polynomial. See svm for more details.

gamma

parameter needed for all kernels except linear. See svm for more details.

coef0

parameter needed for kernels of type polynomial and sigmoid. See svm for more details.

cost

cost of constraints violation (default: 1) - it is the C-constant of the regularization term in the Lagrange formulation. See svm for more details.

nu

parameter needed for nu-classification. See svm for more details.

class.weights

a named vector of weights for the different classes, used for asymmetric class sizes. Not all factor levels have to be supplied (default weight: 1). All components have to be named. See svm for more details.

cachesize

cache memory in MB (default 40). See svm for more details.

tolerance

tolerance of termination criterion (default 0.001). See svm for more details.

epsilon

epsilon in the insensitive-loss function (default: 0.1). See svm for more details.

shrinking

option whether to use the shrinking-heuristics (default: TRUE). See svm for more details.

cross

if a integer value k>0 is specified, a k-fold cross validation on the training data is performed to assess the quality of the model: the accuracy rate for classification. See svm for more details.

probability

logical indicating whether the model should allow for probability predictions. See svm for more details.

fitted

logical indicating whether the fitted values should be computed and included in the model or not. See svm for more details.

seed

integer seed for libsvm. See svm for more details.

subset

an index vector specifying the cases to be used in the training sample. (NOTE: If given, this argument must be named). See svm for more details.

na.action

A function to specify the action to be taken if NAs are found. The default action is na.omit, which leads to rejection of cases with missing values on any required variable. An alternative is na.fail, which causes an error if NA cases are found. (NOTE: If given, this argument must be named). See svm for more details.

Details

Internally, this function uses the svm function available in the e1071 package.

Value

list

An object to be used in classifyEEG.

Author(s)

Murilo Coutinho Silva (coutinho.stat@gmail.com), George Freitas von Borries

References

Hastie, T., Tibshirani, R., Friedman, J. (2009) The Elements of Statistical Learning: Data Mining, Inference, and Prediction. 2nd ed. Stanford: Springer.

Karatzoglou, A., Meyer, D., Hornik, K. (2006) Support Vector Machines in R. Journal of Statistical Software. Vol 15, issue 9.

See Also

classifyEEG, FeatureEEG, svm

Examples

library(eegAnalysis)

###Simulating the data set.
Sim <- randEEG(n.class=2,n.rec=10,n.signals=50,n.channels = 2, 
vars = c(2,1)) 

### Uncomment the next line to choose your own features
# features<-easyFeatures()


### Selecting the features
### The selected features may differ because the algorithm
### uses some random functions
### Obs: features="example" is used to be fast. Use features="default"
### or choose your own set of features.
x<-FeatureEEG(Sim$data,Sim$classes.Id,Sim$rec.Id,features="example",
               Alpha=0.05, AlphaCorr=0.9,minacc=0.8,fast=FALSE)


### Calculating the classifier
y<-svmEEG(x)
y$model 


### Generating new data to test the classifier
new <- randEEG(n.class=2,n.rec=30,n.signals=50,n.channels = 2, 
                      vars = c(2,1)) 


### Classifying the new data and counting the number of successes
cont = 0
for(i in 1:30)
{
  data<-new$data[which((new$classes.Id==1)&(new$rec.Id==i)),]
  if(classifyEEG(y,data)[2]==1)  cont = cont + 1
}

for(i in 1:30)
{
  data<-new$data[which((new$classes.Id==2)&(new$rec.Id==i)),]
  if(classifyEEG(y,data)[2]==2)  cont = cont + 1
}

### The correct classification rate:
cont/60

Results