baseSVM: Prediction by SVM

View source: R/BioMM.R

baseSVMR Documentation

Prediction by SVM

Description

Prediction by support vector machine (SVM) with two different settings: 'classification' and 'regression'.

Usage

baseSVM(
  trainData,
  testData,
  predMode = c("classification", "probability", "regression"),
  paramlist = list(tuneP = TRUE, kernel = "radial", gamma = 10^(-3:-1), cost =
    10^(-2:2))
)

Arguments

trainData

The input training dataset. The first column is the label or the output. For binary classes, 0 and 1 are used to indicate the class member.

testData

The input test dataset. The first column is the label or the output. For binary classes, 0 and 1 are used to indicate the class member.

predMode

The prediction mode. Available options are c('classification', 'probability', 'regression').

paramlist

A set of model parameters defined in an R list object. The valid option: list(kernel, gamma, cost, tuneP).

  1. 'tuneP': a logical value indicating if hyperparameter tuning should be conducted or not. The default is FALSE.

  2. 'kernel': options are c('linear', 'polynomial', 'radial', 'sigmoid'). The defaut is 'radial'.

  3. 'gamma': the parameter needed for all kernels except 'linear'. If tuneP is TRUE, more than one value is suggested.

  4. 'cost': is the cost of constraints violation. If tuneP is TRUE, more than one value is suggested.

Details

Hyperparameter tuning is recommended in many biological data mining applications. The best parameters can be determined via an internal cross validation.

Value

The predicted output for the test data.

Author(s)

Junfang Chen

See Also

svm

Examples

 
## Load data  
methylfile <- system.file('extdata', 'methylData.rds', package='BioMM')  
methylData <- readRDS(methylfile)  
dataY <- methylData[,1]
## select a subset of genome-wide methylation data at random
methylSub <- data.frame(label=dataY, methylData[,c(2:2001)])  
trainIndex <- sample(nrow(methylSub), 12)
trainData = methylSub[trainIndex,]
testData = methylSub[-trainIndex,]
library(e1071)
predY <- baseSVM(trainData, testData, 
                 predMode='classification', 
                 paramlist=list(tuneP=FALSE, kernel='radial', 
                                gamma=10^(-3:-1), cost=10^(-3:1))) 
testY <- testData[,1]
accuracy <- classifiACC(dataY=testY, predY=predY)
print(accuracy) 

transbioZI/BioMMex documentation built on Jan. 27, 2023, 4:14 a.m.