Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. svm.fit <- svm(label ~ NDAI + SD + CORR, data = trainSet, scale = FALSE, kernel = "radial", cost = 2, probability=TRUE)
  2. svm.pred <- predict(svm.fit, testSet, probability=TRUE)
  3. mean(svm.pred== testSet$label)*100
  4.  
  5. prediction.svm <- prediction(attr(svm.pred, "probabilities")[,2], testSet$label)
  6. eval.svm <- performance(prediction.svm, "acc")
  7. roc.svm <- performance(prediction.svm, "tpr", "fpr")
  8.  
  9. #identify best values and cutoff
  10. max_index.svm <- which.max(slot(eval.svm, "y.values")[[1]])
  11. max.acc_svm <- (slot(eval.svm, "y.values")[[1]])[max_index.svm]
  12. opt.cutoff_svm <- (slot(eval.svm, "x.values")[[1]])[max_index.svm][[1]]
  13. #AUC
  14. auc.svm <- performance(prediction.svm, "auc")
  15. auc.svm <- unlist(slot(auc.svm, "y.values"))
  16. auc.svm <- round(auc.svm, 4)
  17.  
  18. plot(roc.svm,colorize=TRUE)
  19. points(0.072, 0.93, pch= 20)
  20. legend(.6,.2, auc.svm, title = "AUC", cex = 0.8)
  21. legend(.8,.2, round(opt.cutoff_svm,4), title = "cutoff", cex = 0.8)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement