How to do it...

Perform the following steps to generate two different classification examples with different costs:

  1. First, you should install and load the ROCR package:
        > install.packages("ROCR")
        > library(ROCR)  
  1. Train the svm model using the training dataset with a probability equal to TRUE:
        > svmfit=svm(churn~ ., data=trainset, prob=TRUE)
  1. Make predictions based on the trained model on the testing dataset with the probability set as TRUE:
        >pred=predict(svmfit,testset[, !names(testset) %in% c("churn")],
probability=TRUE)
  1. Obtain the probability of labels with yes:
        > pred.prob = attr(pred, "probabilities") 
        > pred.to.roc = pred.prob[, 2] 
  1. Use the prediction function to generate a prediction result:
        > pred.rocr = prediction(pred.to.roc, testset$churn)  
  1. Use the performance function to obtain the performance measurement:
        > perf.rocr = performance(pred.rocr, measure = "auc", x.measure =
"cutoff") > perf.tpr.rocr = performance(pred.rocr, "tpr","fpr")
  1. Visualize the ROC curve using the plot function:
        > plot(perf.tpr.rocr, colorize=T,
main=paste("AUC:",([email protected])))
The ROC curve for the svm classifier performance
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset