-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaggregateResults.R
229 lines (200 loc) · 10.7 KB
/
aggregateResults.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
library(tidyverse)
wontieloss <- function(baseforWontieloss,includeToACCdifference,basefolder,filenames,col_names,extrastats=TRUE, decreaseInModelSize=FALSE, AUC=FALSE,reverseDifference=FALSE)
{
statistics<-c("accuracy (macro average)","won/tie/loss", "p-value (accuracy difference)")
if (extrastats)
{
statistics <- c(statistics, "avg number of rules","avg conditions / rule","avg conditions / model","median build time [s]", "median build time norm","mean build time [s]", "mean build time norm")
}
if (decreaseInModelSize)
{
statistics <- c(statistics,"decrease in model size (avg)", "decrease in model size (max)","decrease in model size (min)")
}
if (AUC)
{
statistics <- c(statistics,"AUC (macro average)")
}
result <- data.frame(matrix(rep(0,length(col_names)*length(statistics)), ncol = length(col_names), nrow = length(statistics)), row.names = statistics)
df_base <- NULL
colnames(result) <- col_names
col=0
for (filename in filenames)
{
message(filename)
col=col+1
df<-read_csv(paste(basefolder,"/",filename,sep=""))
message("ommitting KDD datasets if any")
df<- df[!grepl("kdd",df$dataset), ]
result["accuracy (macro average)",col]<-round(mean(df$accuracy),2)
if (baseforWontieloss[col])
{
result["won/tie/loss",col] <- ""
df_base <- df
base_filename <- filename
}
else{
colnames(df)
colnames(df_base)
merged <- merge(df,df_base,by="dataset",suffixes=c("_current","_base"))
accuracy_current_not_rounded <-merged$accuracy_current
accuracy_base_not_rounded <- merged$accuracy_base
merged$accuracy_current<-round(merged$accuracy_current,2)
merged$accuracy_base<-round(merged$accuracy_base,2)
pValue <- wilcox.test(merged$accuracy_current, merged$accuracy_base, paired=TRUE)$p.value
won <-sum(merged$accuracy_current>merged$accuracy_base)
tie <-sum(merged$accuracy_current==merged$accuracy_base)
loss <-sum(merged$accuracy_current<merged$accuracy_base)
if (includeToACCdifference[col]){
if (!reverseDifference)
{
acc_diff<-as.numeric(merged$accuracy_current>merged$accuracy_base)
}
else
{
acc_diff<-as.numeric(merged$accuracy_base>merged$accuracy_current)
}
dfDiff<-data.frame(merged$dataset,acc_diff)
colnames(dfDiff)<-c("dataset",filename)
dfAcc<-data.frame(merged$dataset,accuracy_base_not_rounded,accuracy_current_not_rounded)
colnames(dfAcc)<-c("dataset",base_filename,filename)
if (file.exists("accdifferencebydataset.csv"))
{
df_t<-read_csv("accdifferencebydataset.csv")
dfDiff<-merge(df_t,dfDiff, by="dataset",all = TRUE)
}
if (file.exists("accbydataset.csv"))
{
df_t2<-read_csv("accbydataset.csv")
dfAcc<-merge(df_t2,dfAcc, by="dataset",all = TRUE)
}
write.csv(dfDiff,"accdifferencebydataset.csv",row.names = FALSE)
write.csv(dfAcc,"accbydataset.csv",row.names = FALSE)
print(filename)
}
#end new
result["won/tie/loss",col] <- c(paste0(won,"/",tie,"/",loss))
result["p-value (accuracy difference)",col] <- round(pValue,3)
if(decreaseInModelSize)
{
# micro average
merged$size_ratio <- (merged$rules_current * merged$antlength_current)/(merged$rules_base * merged$antlength_base)
# macro average
# merged$size_ratio <- (mean(merged$rules_current) * mean(merged$antlength_current))/(mean(merged$rules_base) * mean(merged$antlength_base))
result["decrease in model size (avg)",col]<-paste(round(1-mean(merged$size_ratio),4)*100, "%")
result["decrease in model size (max)",col]<-paste(round(1-min(merged$size_ratio),4)*100, "%")
result["decrease in model size (min)",col]<-paste(round(1-max(merged$size_ratio),4)*100, "%")
#stop()
}
}
if (extrastats)
{
result["avg number of rules" ,col]<-round(mean(df$rules),1)
result["avg conditions / rule" ,col]<-round(mean(df$antlength),1)
#macro
result["avg conditions / model (macro)",col]<-round(mean(df$rules)*mean(df$antlength),1)
#micro
result["avg conditions / model (micro)",col]<-round(mean(df$rules*df$antlength),1)
#MEDIAN
buildtime_med<-round(median(df$buildtime),1)
result["median build time [s]",col]<-buildtime_med
#MEAN
buildtime_me<-round(mean(df$buildtime),1)
se <- round(sqrt(var(df$buildtime) / length(df$buildtime)),1)
result["mean build time [s]",col]<-paste(buildtime_me, "+/-",se)
if (baseforWontieloss[col])
{
result["median build time norm",col]<-1.0
buildtimeRef <-median(df$buildtime)
}
else
{
result["median build time norm",col]<-round(median(df$buildtime)/buildtimeRef,2)
}
if (baseforWontieloss[col])
{
result["mean build time norm",col]<-1.0
buildtimeRef_mean <-mean(df$buildtime)
}
else
{
result["mean build time norm",col]<-round(mean(df$buildtime)/buildtimeRef_mean,2)
}
}
if (AUC)
{
if (length(df$auc[df$auc==0])>0){
message("replacing values in the AUC column with NA")
df$auc[df$auc==0] <- NA
}
result["AUC (macro average)",col]<-round(mean(df$auc,na.rm=TRUE),2)
}
}
write.csv(result,paste(basefolder,"/stats.csv",sep=""))
return(result)
}
if (file.exists("accdifferencebydataset.csv"))
{
unlink("accdifferencebydataset.csv")
unlink("accbydataset.csv")
}
# IDS
baseforWontieloss<-c(TRUE,FALSE,FALSE,FALSE,FALSE)
includeToACCdifference<-c(FALSE,TRUE,FALSE,FALSE,FALSE)
basefolder<-"IDS_results"
filenames<-c("IDS.csv","IDSQCBA_R_noPruning_ATTPRUNING_TRUE.csv", "IDSQCBA_R_transactionBased_ATTPRUNING_TRUE.csv", "IDSQCBA_R_noPruning_ATTPRUNING_FALSE.csv","IDSQCBA_R_transactionBased_ATTPRUNING_FALSE.csv")
col_names<-c("only IDS","IDS+QCBA #5","IDS+QCBA #6","IDS+QCBA #5 No AttPruning","IDS+QCBA #6 No AttPruning")
result<-wontieloss(baseforWontieloss,includeToACCdifference,basefolder,filenames,col_names)
result
# CBA # auc datasets
baseforWontieloss<-c(TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE)
includeToACCdifference<-c(FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE)
basefolder<-"CBA_results"
filenames<-c("117-noExtend-D-mci=-1-cba.csv","120-noExtend-mci=-1-qcba.csv", "114-noExtend-A-mci=-1-qcba.csv", "42-noExtend-T-A-mci=-1-qcba.csv", "186-numericOnly-T-A-mci=-1-qcba.csv", "198-numericOnly-T-Pcba-A-mci=-1-qcba.csv", "196-numericOnly-T-Pcba-A-transactionBased-mci=-1-qcba.csv", "197-numericOnly-T-Pcba-A-rangeBased-mci=-1-qcba.csv")
col_names<-c("only CBA","CBA+QCBA #1 (+ refit)","CBA+QCBA #2 (+att pruning)", "CBA+QCBA #3 (+trimming)","CBA+QCBA #4 (+extension)","CBA+QCBA #5 (+postpruning)","CBA+QCBA #6 (+tran. based pruning)","CBA+QCBA #7 (+rangeBased pruning)")
result<-wontieloss(baseforWontieloss,includeToACCdifference,basefolder,filenames,col_names, extrastats=TRUE,decreaseInModelSize=FALSE, AUC=TRUE)
result
# SBRL
#SBRL+QCBA is compared against SBRL only,
#i.e. TRUE means that SBRL-1.csv will be used as a base accuracy to compare against for both SBRLQCBA-noPruning-1.csv and SBRLQCBA-transactionBased-1.csv
baseforWontieloss<-c(TRUE,FALSE,FALSE,TRUE,FALSE,FALSE)
includeToACCdifference<-c(FALSE,FALSE,FALSE,FALSE,TRUE,FALSE)
basefolder<-"SBRL_results"
filenames<-c("SBRL-1.csv","SBRLQCBA-noPruning-1.csv", "SBRLQCBA-transactionBased-1.csv","SBRL-Long.csv", "SBRLQCBA-noPruning-Long.csv","SBRLQCBA-transactionBased-Long.csv")
col_names<-c("only SBRL (Short)","SBRL+QCBA (Short) #5","SBRL+QCBA (Short) #6","only SBRL (long)","SBRL+QCBA (long) #5","SBRL+QCBA (long) #6")
result<-wontieloss(baseforWontieloss,includeToACCdifference,basefolder,filenames,col_names)
result
# summary of effects of postprocessing by QCBA#5
baseforWontieloss<-c(TRUE,FALSE,FALSE,TRUE,FALSE,TRUE,FALSE)
includeToACCdifference<-c(FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE)
basefolder<-"QCBA_eval_IDS_SBRL"
filenames<-c("../CBA_results/120-noExtend-mci=-1-cba.csv","../CBA_results/117-noExtend-D-mci=-1-cba.csv","../CBA_results/198-numericOnly-T-Pcba-A-mci=-1-qcba.csv", "../SBRL_results/SBRL-Long.csv", "../SBRL_results/SBRLQCBA-noPruning-Long.csv", "../IDS_results/IDS.csv", "../IDS_results/IDSQCBA_R_noPruning_ATTPRUNING_TRUE.csv" )
col_names<-c("CBA(dc)","CBA(dc+dr)","CBA(dc)+QCBA#5","SBRL","SBRL+QCBA#5" ,"IDS","IDS+QCBA#5")
result<-wontieloss(baseforWontieloss,includeToACCdifference,basefolder,filenames,col_names,extrastats=FALSE,decreaseInModelSize=TRUE)
result
# FOIL2+QCBA#5 against other symbolic learners
baseforWontieloss<-c(TRUE,FALSE,FALSE,FALSE,FALSE,FALSE)
includeToACCdifference<-c(FALSE,TRUE,TRUE,TRUE,TRUE,TRUE)
basefolder<-"WEKA_results"
filenames<-c("../CBA_results/198-numericOnly-T-Pcba-A-mci=-1-qcba.csv", "../CORELS_results/CORELS.csv", "J48-accuracy.csv","PART-accuracy.csv", "RIPPER-accuracy.csv", "FURIA-accuracy_missing_omitted.csv")
col_names<-c("CBA+QCBA #5","CORELS", "J48","PART","RIPPER", "FURIA")
#reverseDifference=TRUE: the reason is that baseforWontieloss is a QCBA model but in other calls to wontieloss it is the non-QCBA model.
result<-wontieloss(baseforWontieloss,includeToACCdifference,basefolder,filenames,col_names,extrastats=FALSE, reverseDifference=TRUE)
result
# QCBA#5 against other rule learners
baseforWontieloss<- c(TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE)
includeToACCdifference<-c(FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE)
basefolder<-"QCBA_eval_PRM_FOIL2_CMAR_CPAR"
filenames<-c("../CMAR_results/CMAR-default_mci-1-noPruning.csv","../CMAR_results/CMAR_QCBA-default_mci-1-noPruning.csv","../CPAR_results/CPAR-default_mci-1-noPruning.csv","../CPAR_results/CPAR_QCBA-default_mci-1-noPruning.csv","../FOIL2_results/FOIL2-default_mci-1-noPruning.csv","../FOIL2_results/FOIL2_QCBA-default_mci-1-noPruning.csv","../PRM_results/PRM-default_mci-1-noPruning.csv","../PRM_results/PRM_QCBA-default_mci-1-noPruning.csv")
col_names<-c("CMAR","CMAR+QCBA #5","CPAR","CPAR+QCBA #5","FOIL2","FOIL2+QCBA #5","PRM","PRM+QCBA #5")
result<-wontieloss(baseforWontieloss,includeToACCdifference,basefolder,filenames,col_names)
result
df_acc<-read_csv("accbydataset.csv")
best<-colnames(df_acc)[apply(df_acc,1,which.max)]
n<-ncol(df_acc)-1
df<-read_csv("accdifferencebydataset.csv")
#how many perecent of recorded results are wins (for some algorithms and datasets, there are no results)
df$qcbawins<-rowSums(df[,-1],na.rm=TRUE)/rowSums(!is.na(df[,-1]))
df$max <- do.call(pmax, c(df_acc[2:n], list(na.rm=TRUE)))
df$bestAlg<-best
write.csv(df,"accdifferencebydataset.csv",row.names = FALSE)
print("Statistics of the number of wins of QCBA by dataset and baseline algorithm and best algorithm and result for each dataset saved written to accdifferencebydataset.csv")