calculate accuracy of linear model R code example
Example: classification accuracy metric in r
ClassificationAccuracyMetric <- function (Actual, Predicted){
TP <- 0
FN <- 0
FP <- 0
TN <- 0
for (i in 1:length(Actual)){
if (Actual[i]==0 & Predicted[i]==0){
TP=TP+1
}
if (Actual[i]==0 & Predicted[i]==1){
FN=FN+1
}
if (Actual[i]==1 & Predicted[i]==0){
FP=FP+1
}
if (Actual[i]==1 & Predicted[i]==1){
TN=TN+1
}
}
return ((TN + TP)/(TN + TP + FN + FP))
}
print(ClassificationAccuracyMetric( c(1,1,0,0,1,0,1,1,1,1), c(1,1,0,0,1,0,1,1,1,0) ))