-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
reducingResultsByLearner.R
60 lines (49 loc) · 2.28 KB
/
reducingResultsByLearner.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
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
# * Example:
# devtools::load_all()
# source("reducingResultsByLearner")
# reducingResultsByLearner(lrn = "classif.rpart")
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
reducingResultsByLearner = function(reg, lrn = NULL){
if(is.null(lrn)) {
stopf("Please, give a learner name!")
}
if(!dir.exists("output/")) {
dir.create(path = "output/", recursive = TRUE)
}
df = getJobInfo(reg)
save(x = df, file = paste0("output/allJobsInfo.RData"))
algos.names = gsub(pattern=".preproc|.imputed", replacement="", x=unique(df$algo))
if(is.null(lrn) || lrn %nin% algos.names) {
stopf("There is no results for this learner. Please, provide a valid name.")
}
fn.filter = function(job, res){
algo = gsub(pattern=".preproc|.imputed", replacement="", x=unique(job$algo.id))
return(algo == lrn)
}
sel.ids = filterResults(reg = reg, ids = getJobIds(reg), fun = fn.filter)
cat(" - ", length(sel.ids), "job(s) was(were) found for learner:\'",lrn,"\'\n")
par.set = getHyperSpace(learner = makeLearner(lrn), p = 1, n = 100)
if(length(par.set$pars) == 0) {
impute.pars = list()
} else {
impute.pars = lapply(par.set$pars, function(par) NA)
}
# Also reduce jobs with errors | unfinished
data = reduceResultsList(reg, ids = sel.ids, impute.val = impute.pars,
fun = function(aggr, job, res) {
temp = rbind(data.frame(id = job$id, prob = job$prob.id, algo = job$algo.id,
repl = job$repl, y = res, stringsAsFactors = FALSE))
return(temp)
}
)
ret = do.call("rbind", data)
output.file = paste0(gsub(x = lrn, pattern = "\\.", replacement = "_"), "_space")
write.csv(x = ret, file = paste0("output/", output.file, ".csv"))
save(x = ret, file = paste0("output/", output.file, ".RData"))
return(ret)
}
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------