-
Notifications
You must be signed in to change notification settings - Fork 2
/
mainMTL.R
108 lines (88 loc) · 4.31 KB
/
mainMTL.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
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
mainMTL = function(parsed.obj) {
devtools::load_all()
parsed.obj$norm = as.logical(parsed.obj$norm)
parsed.obj$seed = as.integer(parsed.obj$seed)
if(is.null(parsed.obj$models)) {
parsed.obj$models = FALSE
} else {
parsed.obj$models = TRUE
}
#-------------------------------------
# check parameters passed to mainMTL
#-------------------------------------
sub.data = gsub(x = list.files(path = "data/"), pattern = ".arff", replacement = "")
checkmate::assertChoice(x = parsed.obj$datafile, choices = sub.data, .var.name = "datafile")
checkmate::assertChoice(x = parsed.obj$resamp, choices = AVAILABLE.RESAMPLING)
checkmate::assertChoice(x = parsed.obj$feat.sel, choices = AVAILABLE.FEATSEL)
checkmate::assertChoice(x = parsed.obj$tuning, choices = AVAILABLE.TUNING)
checkmate::assertChoice(x = parsed.obj$balancing, choices = AVAILABLE.BALANCING)
checkmate::assertLogical(x = parsed.obj$norm)
checkmate::assertInt(x = parsed.obj$seed, lower = 1, upper = 30, .var.name = "seed")
#-------------------------------------
# check possible combinations
#-------------------------------------
if(grepl(pattern = "regr", x = parsed.obj$algo)) {
assertChoice(x = parsed.obj$algo, choices = AVAILABLE.REGR, .var.name = "algo")
task.type = "regression"
} else if (grepl(pattern = "classif", x = parsed.obj$algo)) {
assertChoice(x = parsed.obj$algo, choices = AVAILABLE.CLASS, .var.name = "algo")
task.type = "classification"
} else {
stop("Invalid algo option\n")
}
if(task.type == "regression" & parsed.obj$balancing != "none") {
stop("Balancing is not available for regression tasks \n")
}
#-------------------------------------
# main execution
#-------------------------------------
cat(" ---------------------------- \n")
cat(" **** Meta-learning **** \n")
cat(" ---------------------------- \n")
cat(paste0(" - Datafile: \t", parsed.obj$datafile, "\n"))
cat(paste0(" - Algo: \t", parsed.obj$algo, "\n"))
cat(paste0(" - Feat.Sel: \t", parsed.obj$feat.sel, "\n"))
cat(paste0(" - Norm: \t", parsed.obj$norm, "\n"))
cat(paste0(" - Resamp: \t", parsed.obj$resamp, "\n"))
cat(paste0(" - Tuning: \t", parsed.obj$tuning, "\n"))
cat(paste0(" - Balancing: \t", parsed.obj$balancing, "\n"))
cat(paste0(" - Seed: \t", parsed.obj$seed, "\n"))
if(parsed.obj$models) {
cat(paste0(" - Exporting models\n"))
}
cat(" ---------------------------- \n")
runMetaLearning(parsed.obj = parsed.obj, task.type = task.type)
cat("\n - Finished!\n")
cat(" ---------------------------- \n")
}
# -------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
options(echo = TRUE)
args = commandArgs(trailingOnly = TRUE)
option_list = list(
optparse::make_option(c("--datafile"), type="character", action="store",
help="dataset's filename"),
optparse::make_option(c("--algo"), type="character", action="store",
help="ML algorithm"),
optparse::make_option(c("--norm"), type="logical", action="store",
help="perform data normalization"),
optparse::make_option(c("--feat.sel"), type="character", action="store",
help="perform feature selection"),
optparse::make_option(c("--resamp"), type="character", action="store",
help="resampling strategy"),
optparse::make_option(c("--tuning"), type="character", action="store",
help="tuning technique"),
optparse::make_option(c("--balancing"), type="character", action="store",
help="data balancing technique"),
optparse::make_option(c("--seed"), type="integer", action="store",
help="seed for reproducibility"),
optparse::make_option(c("--models"), action="store_true",
help="should it export models?")
)
parsed.obj = optparse::parse_args(optparse::OptionParser(option_list=option_list), args = args)
print(parsed.obj)
mainMTL(parsed.obj = parsed.obj)
#--------------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------------