R Functions : AUC and KS

Live Online Training : Data Science with R

- Explain Advanced Algorithms in Simple English
- Live Projects
- Case Studies
- Job Placement Assistance
- Get 10% off till Oct 26, 2017
- Batch starts from October 28, 2017

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])

R Tutorials : 75 Free R Tutorials

About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has close to 7 years of experience in data science and predictive modeling. During his tenure, he has worked with global clients in various domains like retail and commercial banking, Telecom, HR and Automotive.

While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

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

Next → ← Prev