-
Notifications
You must be signed in to change notification settings - Fork 2
/
bcw-utils-perf.R
25 lines (21 loc) · 1.03 KB
/
bcw-utils-perf.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
## True positives (TP) - Positive labeled correctly
## True negatives (TN) - Negative labeled correctly
## False positives (FP) - Positive labeled wrongly
## False negatives (FN) - Negative labeled wrongly
bcw.calculateFMeasure <- function(bcw.data) {
TP <- nrow(bcw.data[(bcw.data$class == 4 & bcw.data$predict == 4), ])
TN <- nrow(bcw.data[(bcw.data$class == 2 & bcw.data$predict == 2), ])
FP <- nrow(bcw.data[(bcw.data$class == 2 & bcw.data$predict == 4), ])
FN <- nrow(bcw.data[(bcw.data$class == 4 & bcw.data$predict == 2), ])
Precision <- TP / (TP+FP)
Recall <- TP / (TP+FN)
return ((2 * Precision * Recall) / (Precision + Recall))
}
bcw.calculateAccuracy <- function(bcw.data) {
TP <- nrow(bcw.data[(bcw.data$class == 4 & bcw.data$predict == 4), ])
TN <- nrow(bcw.data[(bcw.data$class == 2 & bcw.data$predict == 2), ])
FP <- nrow(bcw.data[(bcw.data$class == 2 & bcw.data$predict == 4), ])
FN <- nrow(bcw.data[(bcw.data$class == 4 & bcw.data$predict == 2), ])
Accuracy <- (TP+TN) / (TP+FP+TN+FN)
return (Accuracy)
}