If ROCR package is not installed on your machine, please install it before running the following functions.
Parameters
Parameters
- pred - Predicted probability column of event (interesting class)
- 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){
require("ROCR")
p <- prediction(as.numeric(pred),depvar)
auc <- performance(p,"auc")
auc <- unlist(slot(auc, "y.values"))
return(auc)
}
KS <- function(pred,depvar){
require("ROCR")
p <- prediction(as.numeric(pred),depvar)
perf <- performance(p, "tpr", "fpr")
ks <- max(attr(perf, "y.values")[[1]] - (attr(perf, "x.values")[[1]]))
return(ks)
}
KS(rfPred[,2], dev[,1])
AUC(rfPred[,2], dev[,1])
Share Share Tweet