-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_precisionRecallSummary_list.R
169 lines (117 loc) · 5.4 KB
/
create_precisionRecallSummary_list.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
create_precisionRecallSummary_list <- function(container, classification_results, b_value=1) {
confusion <- function(true,pred) {
conf_out <- table(factor(true,levels=sort(unique(true))),factor(pred,levels=sort(unique(true))))
return(conf_out)
}
precision <- function(confusion) {
correct <- diag(confusion)
precision_sums <- colSums(confusion)
precision_out <- round (correct/precision_sums,2)
return(precision_out)
}
recall <- function(confusion) {
correct <- diag(confusion)
recall_sums <- rowSums(confusion)
recall_out <- round (correct/recall_sums,2)
return(recall_out)
}
# takes v_value set to 1 weighs precision/recall equally; vector of precision values, vector recall values
fscore <- function(b_value,precision,recall){
B <- b_value
fscore <- ((B^2+1) * precision * recall) / ((B^2 * precision) + recall)
return(fscore)
}
fscores_out <- function(b_value,precision,recall) {
fscores_out <- NULL
for (i in seq_along(precision)) {
fscores_out[i] <- round(fscore(b_value,precision[i],recall[i]),2)
}
return(fscores_out)
}
scores <- create_scoreSummary_list(container, classification_results)
true <- container[2][[1]]
columns <- colnames(scores)
results <- c()
if (pmatch("SVM_LABEL",columns,nomatch=0) > 0) {
pred <- scores$SVM_LABEL
conf <- confusion(true,pred)
svm_precision <- precision(conf)
svm_recall <- recall(conf)
svm_fscore <- fscores_out (b_value,svm_precision,svm_recall)
svm_results <- cbind(SVM_PRECISION=svm_precision,SVM_RECALL=svm_recall,SVM_FSCORE=svm_fscore)
results <- cbind(results,svm_results)
}
if (pmatch("SLDA_LABEL",columns,nomatch=0) > 0) {
pred <- scores$SLDA_LABEL
conf <- confusion(true,pred)
slda_precision <- precision(conf)
slda_recall <- recall(conf)
slda_fscore <- fscores_out (b_value,slda_precision,slda_recall)
slda_results <- cbind(SLDA_PRECISION=slda_precision,SLDA_RECALL=slda_recall,SLDA_FSCORE=slda_fscore)
results <- cbind(results,slda_results)
}
if (pmatch("LOGITBOOST_LABEL",columns,nomatch=0) > 0) {
pred <- scores$LOGITBOOST_LABEL
conf <- confusion(true,pred)
boosting_precision <- precision(conf)
boosting_recall <- recall(conf)
boosting_fscore <- fscores_out (b_value,boosting_precision,boosting_recall)
boosting_results <- cbind(LOGITBOOST_PRECISION=boosting_precision,LOGITBOOST_RECALL=boosting_recall,LOGITBOOST_FSCORE=boosting_fscore)
results <- cbind(results,boosting_results)
}
if (pmatch("BAGGING_LABEL",columns,nomatch=0) > 0) {
pred <- scores$BAGGING_LABEL
conf <- confusion(true,pred)
bagging_precision <- precision(conf)
bagging_recall <- recall(conf)
bagging_fscore <- fscores_out (b_value,bagging_precision,bagging_recall)
bagging_results <- cbind(BAGGING_PRECISION=bagging_precision,BAGGING_RECALL=bagging_recall,BAGGING_FSCORE=bagging_fscore)
results <- cbind(results,bagging_results)
}
if (pmatch("FORESTS_LABEL",columns,nomatch=0) > 0) {
pred <- scores$FORESTS_LABEL
conf <- confusion(true,pred)
rf_precision <- precision(conf)
rf_recall <- recall(conf)
rf_fscore <- fscores_out (b_value,rf_precision,rf_recall)
rf_results <- cbind(FORESTS_PRECISION=rf_precision,FORESTS_RECALL=rf_recall,FORESTS_FSCORE=rf_fscore)
results <- cbind(results,rf_results)
}
if (pmatch("GLMNET_LABEL",columns,nomatch=0) > 0) {
pred <- scores$GLMNET_LABEL
conf <- confusion(true,pred)
glmnet_precision <- precision(conf)
glmnet_recall <- recall(conf)
glmnet_fscore <- fscores_out (b_value,glmnet_precision,glmnet_recall)
glmnet_results <- cbind(GLMNET_PRECISION=glmnet_precision,GLMNET_RECALL=glmnet_recall,GLMNET_FSCORE=glmnet_fscore)
results <- cbind(results,glmnet_results)
}
if (pmatch("TREE_LABEL",columns,nomatch=0) > 0) {
pred <- scores$TREE_LABEL
conf <- confusion(true,pred)
tree_precision <- precision(conf)
tree_recall <- recall(conf)
tree_fscore <- fscores_out (b_value,tree_precision,tree_recall)
tree_results <- cbind(TREE_PRECISION=tree_precision,TREE_RECALL=tree_recall,TREE_FSCORE=tree_fscore)
results <- cbind(results,tree_results)
}
if (pmatch("NNETWORK_LABEL",columns,nomatch=0) > 0) {
pred <- scores$NNETWORK_LABEL
conf <- confusion(true,pred)
nnet_precision <- precision(conf)
nnet_recall <- recall(conf)
nnet_fscore <- fscores_out (b_value,nnet_precision,nnet_recall)
nnet_results <- cbind(NNETWORK_PRECISION=nnet_precision,NNETWORK_RECALL=nnet_recall,NNETWORK_FSCORE=nnet_fscore)
results <- cbind(results,nnet_results)
}
if (pmatch("MAXENTROPY_LABEL",columns,nomatch=0) > 0) {
pred <- scores$MAXENTROPY_LABEL
conf <- confusion(true,pred)
maxent_precision <- precision(conf)
maxent_recall <- recall(conf)
maxent_fscore <- fscores_out (b_value,maxent_precision,maxent_recall)
maxent_results <- cbind(MAXENTROPY_PRECISION=maxent_precision,MAXENTROPY_RECALL=maxent_recall,MAXENTROPY_FSCORE=maxent_fscore)
results <- cbind(results,maxent_results)
}
return(results)
}