Created
December 21, 2018 05:19
-
-
Save sudevschiz/f5e6455df06bdb048bdedc268123e6b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### Function to validate classification models#### | |
accuracy_metrics <- function(y_actual, y_predicted) { | |
#Check if the input is factor | |
if(is.factor(y_actual)){ | |
print("Info : Actual values provided as factor. Factor converted to numeric. ") | |
#Convert to numeric | |
y_actual <- as.numeric(y_actual) - 1 | |
} | |
if(is.factor(y_predicted)){ | |
print("Info : Predicted values provided as factor. Factor converted to numeric. ") | |
#Convert to numeric | |
y_predicted <- as.numeric(y_predicted) - 1 | |
} | |
if(is.logical(y_actual)){ | |
print("Info : Predicted values provided as Logical vector. Logical vector converted to numeric. ") | |
#Convert to numeric | |
y_actual<- as.numeric(y_actual) | |
} | |
if(is.logical(y_predicted)){ | |
print("Info : Predicted values provided as Logical vector. Logical vector converted to numeric. ") | |
#Convert to numeric | |
y_predicted<- as.numeric(y_predicted) | |
} | |
# AUC ROC | |
pred_ROCR <- prediction(y_predicted, y_actual) | |
roc_ROCR <- performance(pred_ROCR, measure = "tpr", x.measure = "fpr") | |
plot(roc_ROCR, main = "ROC curve", colorize = T) | |
abline(a = 0, b = 1) | |
auc_ROCR <- performance(pred_ROCR, measure = "auc") | |
auc_ROCR <- [email protected][[1]] | |
print(paste("Area under ROC = ", auc_ROCR)) | |
return(auc_ROCR) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment