Created
March 15, 2017 13:03
-
-
Save sizhky/da0149b81daf0b516a79599658062eae to your computer and use it in GitHub Desktop.
This file contains 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
get_metrics <- function(model, test_data, truth, table = FALSE){ | |
preds <- predict(model, test_data); | |
table_ <- table(truth, preds); | |
acc_ <- sum(diag(table_))/sum(table_); | |
rec_ <- table_[2,2]/sum(table_[,2]); | |
prec_ <- table_[2,2]/sum(table_[2,]); | |
f_ <- 2*rec_*prec_/(rec_+prec_) | |
if (table == FALSE){ | |
cat('Accuracy:', acc_, '\nRecall:', rec_, '\nPrecision:', prec_, '\nF-Score:', f_); | |
} else { | |
return(table_) | |
} | |
# return(c(acc_, rec_, prec_, f_)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment