Page 92
Appendix A
R Programmes Used for Data Analysis in Support Vector Machine
rm (list = ls())
dat = read .table(file='clipboard' ,header=T, sep=",");dat
colnames (dat) =c ("RAD","AGE","HAA","ARP","DOS","FAD", "class");dat
head (dat, n=3)
dat $ class = ifelse (dat $ class==2,-1,1);dat
n = nrow (dat)
TrainIndex = sample (1:n, size = round(0.7*n),replace = FALSE)
Train = dat [TrainIndex,]
Test = dat [-TrainIndex,]
Train = as.matrix (Train)
nrow (Train) + nrow (Test)
library (kernlab)
svp = ksvm (Train[, -7],Train[,7],type="C-svc" ,kernel = 'vanilladot',C=100,scaled=c())
preds = predict (svp, Test [,-7])
CorrectPrediction = sum (Test [,7] = = preds); CorrectPrediction
Accuracy = (CorrectPrediction / nrow (Test))*100
noquote (paste0 ('Accuracy=',Accuracy,'%'))
View publication stats
Dostları ilə paylaş: |