## load transcription factor binding site data
data(TFBS)
enhancerFB
## select 70% of the samples for training and the rest for test
train <- sample(1:length(enhancerFB), length(enhancerFB) * 0.7)
test <- c(1:length(enhancerFB))[-train]
## create the kernel object for gappy pair kernel with normalization
gappy <- gappyPairKernel(k=1, m=1)
## show details of kernel object
gappy
## run training with explicit representation
model <- kbsvm(x=enhancerFB[train], y=yFB[train], kernel=gappy,
pkg="LiblineaR", svm="C-svc", cost=10)
## show feature weights in KeBABS model
featureWeights(model)[1:8]
## predict the test sequences
pred <- predict(model, enhancerFB[test])
evaluatePrediction(pred, yFB[test], allLabels=unique(yFB))
pred[1:10]
## output decision values instead
pred <- predict(model, enhancerFB[test], predictionType="decision")
pred[1:10]
## Not run:
# ## example for training and prediction via precomputed kernel matrix
#
# ## compute quadratic kernel matrix of training samples
# kmtrain <- getKernelMatrix(gappy, x=enhancerFB, selx=train)
#
# ## train model with kernel matrix
# model <- kbsvm(x=kmtrain, y=yFB[train], kernel=gappy,
# pkg="e1071", svm="C-svc", cost=10)
#
# ## compute rectangular kernel matrix of test samples versus
# ## support vectors
# kmtest <- getKernelMatrix(gappy, x=enhancerFB, y=enhancerFB,
# selx=test, sely=train)
#
# ## predict with kernel matrix
# pred <- predict(model, kmtest)
# evaluatePrediction(pred, yFB[test], allLabels=unique(yFB))
#
# ## example for probability model generation during training
#
# ## compute probability model via Platt scaling during training
# ## and predict class membership probabilities
# model <- kbsvm(x=enhancerFB[train], y=yFB[train], kernel=gappy,
# pkg="e1071", svm="C-svc", cost=10, probModel=TRUE)
#
# ## show parameters of the fitted probability model which are the parameters
# ## probA and probB for the fitted sigmoid function in case of classification
# ## and the value sigma of the fitted Laplacian in case of a regression
# probabilityModel(model)
#
# ## predict class probabilities
# prob <- predict(model, enhancerFB[test], predictionType="probabilities")
# prob[1:10]
# ## End(Not run)
Run the code above in your browser using DataLab