predict.ksvm.RdPrediction of test data using support vector machines
# S4 method for class 'ksvm'
predict(object, newdata, type = "response", coupler = "minpair")an S4 object of class ksvm created by the
ksvm function
a data frame or matrix containing new data
one of response, probabilities
,votes, decision
indicating the type of output: predicted values, matrix of class
probabilities, matrix of vote counts, or matrix of decision values.
Coupling method used in the multiclass case, can be one
of minpair or pkpd (see reference for more details).
If type(object) is C-svc,
nu-svc, C-bsvm or spoc-svc
the vector returned depends on the argument type:
predicted classes (the classes with majority vote).
matrix of class probabilities (one column for each class and one row for each input).
matrix of vote counts (one column for each class and one row for each new input)
If type(object) is eps-svr, eps-bsvr or
nu-svr a vector of predicted values is returned.
If type(object) is one-classification a vector of
logical values is returned.
T.F. Wu, C.J. Lin, R.C. Weng.
Probability estimates for Multi-class Classification by
Pairwise Coupling
https://www.csie.ntu.edu.tw/~cjlin/papers/svmprob/svmprob.pdf
H.T. Lin, C.J. Lin, R.C. Weng (2007), A note on Platt's probabilistic outputs for support vector machines. Machine Learning, 68, 267–276. doi:10.1007/s10994-007-5018-6 .
## example using the promotergene data set
data(promotergene)
## create test and training set
ind <- sample(1:dim(promotergene)[1],20)
genetrain <- promotergene[-ind, ]
genetest <- promotergene[ind, ]
## train a support vector machine
gene <- ksvm(Class~.,data=genetrain,kernel="rbfdot",
kpar=list(sigma=0.015),C=70,cross=4,prob.model=TRUE)
gene
#> Support Vector Machine object of class "ksvm"
#>
#> SV type: C-svc (classification)
#> parameter : cost C = 70
#>
#> Gaussian Radial Basis kernel function.
#> Hyperparameter : sigma = 0.015
#>
#> Number of Support Vectors : 81
#>
#> Objective Function Value : -48.1877
#> Training error : 0
#> Cross validation error : 0.116883
#> Probability model included.
## predict gene type probabilities on the test set
genetype <- predict(gene,genetest,type="probabilities")
genetype
#> + -
#> [1,] 0.040542594 0.9594574062
#> [2,] 0.002211444 0.9977885555
#> [3,] 0.952247961 0.0477520387
#> [4,] 0.162376656 0.8376233444
#> [5,] 0.013730040 0.9862699601
#> [6,] 0.992166441 0.0078335587
#> [7,] 0.011286821 0.9887131791
#> [8,] 0.929267462 0.0707325376
#> [9,] 0.003315313 0.9966846875
#> [10,] 0.243736472 0.7562635281
#> [11,] 0.949202927 0.0507970727
#> [12,] 0.042987048 0.9570129515
#> [13,] 0.058022034 0.9419779656
#> [14,] 0.998435629 0.0015643706
#> [15,] 0.999525523 0.0004744769
#> [16,] 0.617304568 0.3826954320
#> [17,] 0.054837853 0.9451621472
#> [18,] 0.809099334 0.1909006662
#> [19,] 0.005802053 0.9941979470
#> [20,] 0.065838895 0.9341611051