Perform the following steps to generate two different classification examples with different costs:
- First, you should install and load the ROCR package:
> install.packages("ROCR") > library(ROCR)
- Train the svm model using the training dataset with a probability equal to TRUE:
> svmfit=svm(churn~ ., data=trainset, prob=TRUE)
- 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)
- Obtain the probability of labels with yes:
> pred.prob = attr(pred, "probabilities") > pred.to.roc = pred.prob[, 2]
- Use the prediction function to generate a prediction result:
> pred.rocr = prediction(pred.to.roc, testset$churn)
- 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")
- 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