R Functions : AUC and KS

If ROCR package is not installed on your machine, please install it before running the following functions.

  1.  pred - Predicted probability column of event (interesting class)
  2. depvar - Dependent / Target / Outcome Variable
Training Dataset Prediction Column
rfPred <- predict(tuned, type ="prob")
Validation Dataset Prediction Column
rfPred <- predict(tuned, val, type ="prob")
R Functions for AUC and KS Statistics

AUC <- function(pred,depvar){
  p   <- prediction(as.numeric(pred),depvar)
  auc <- performance(p,"auc")
  auc <- unlist(slot(auc, "y.values"))
KS <- function(pred,depvar){
  p   <- prediction(as.numeric(pred),depvar)
  perf <- performance(p, "tpr", "fpr")
  ks <- max(attr(perf, "y.values")[[1]] - (attr(perf, "x.values")[[1]]))
KS(rfPred[,2], dev[,1])
AUC(rfPred[,2], dev[,1])
Love this Post? Spread the Word!
Comment and share to motivate us to write more!
About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 8 years of experience in data science. During his tenure, he has worked with global clients in various domains like Banking, Insurance, Telecom and Human Resource.

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*
Related Posts:
0 Response to "R Functions : AUC and KS"

Post a Comment

We have Zero Tolerance to Spam. Comments with links will be deleted immediately upon our review.

Next → ← Prev
Scroll to Top