https://doi.org/10.32614/CRAN.package.penalizedSVM
The goal of penalizedSVM is to support Vector Machine (SVM) classification with simultaneous feature selection using penalty functions is implemented. The smoothly clipped absolute deviation (SCAD), ‘L1-norm’, ‘Elastic Net’ (‘L1-norm’ and ‘L2-norm’) and ‘Elastic SCAD’ (SCAD and ‘L2-norm’) penalties are available. The tuning parameters can be found using either a fixed grid or a interval search.
You can install the released version of peperr from CRAN with:
install.packages("penalizedSVM")
And the development version from GitHub with:
install.packages("devtools")
::install_github("fbertran/penalizedSVM") devtools
This is a basic example.
library(penalizedSVM)
<- 123
seed<-sim.data(n = 200, ng = 100, nsg = 10, corr=FALSE, seed=seed )
trainprint(str(train))
#> List of 3
#> $ x : num [1:100, 1:200] 0.547 0.635 -0.894 0.786 2.028 ...
#> ..- attr(*, "dimnames")=List of 2
#> .. ..$ : chr [1:100] "pos1" "pos2" "pos3" "pos4" ...
#> .. ..$ : chr [1:200] "1" "2" "3" "4" ...
#> $ y : Named num [1:200] 1 -1 -1 1 -1 -1 1 -1 -1 -1 ...
#> ..- attr(*, "names")= chr [1:200] "1" "2" "3" "4" ...
#> $ seed: num 123
#> NULL
Train standard svm
<-svm(x=t(train$x), y=train$y, kernel="linear") my.svm
Test with other data
<- sim.data(n = 200, ng = 100, nsg = 10, seed=(seed+1) ) test
Check accuracy standard SVM
<-ifelse( predict(my.svm, t(test$x)) >0,1,-1) my.pred
Check accuracy:
table(my.pred, test$y)
#>
#> my.pred -1 1
#> -1 81 23
#> 1 30 66