-
Notifications
You must be signed in to change notification settings - Fork 0
/
defs4.R
76 lines (70 loc) · 2.83 KB
/
defs4.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
library(mlr)
library(BBmisc)
learners = list(
makeLearner("classif.rpart"),
makeLearner("classif.ranger", num.trees = 500),
makeLearner("classif.RRF", ntree = 500)
)
# other learners
learners2 = list(
makeLearner(id = "classif.svm.radial", "classif.svm", kernel = "radial"),
makeLearner(id = "classif.svm.polynomial", "classif.svm", kernel = "polynomial"),
makeLearner(id = "classif.svm.linear", "classif.svm", kernel = "linear"),
makeLearner("classif.gbm"),
makeLearner("classif.kknn"),
makeLearner("classif.naiveBayes"),
makeLearner(id = "classif.glmnet.lasso", "classif.glmnet", alpha = 1),
makeLearner(id = "classif.glmnet.ridge", "classif.glmnet", alpha = 0),
makeLearner("classif.C50"),
makeLearner("classif.featureless")
)
# paramset for other learners
ps = list(
classif.svm.radial = makeParamSet(
makeNumericParam("cost", lower = -12, upper = 12, trafo = function(x) 2^x),
makeNumericParam("gamma", lower = -12, upper = 12, trafo = function(x) 2^x)
),
classif.svm.polynomial = makeParamSet(
makeNumericParam("cost", lower = -12, upper = 12, trafo = function(x) 2^x),
makeIntegerParam("degree", lower = 1, upper = 5)
),
classif.svm.linear = makeParamSet(
makeNumericParam("cost", lower = -12, upper = 12, trafo = function(x) 2^x)
),
classif.gbm = makeParamSet(
makeNumericParam("shrinkage", lower = -4, upper = -1, trafo = function(x) 10^x),
makeIntegerParam("interaction.depth", lower = 1, upper = 5),
makeIntegerParam("n.trees", lower = 500, upper = 10000)
),
classif.kknn = makeParamSet(
makeIntegerParam("k", lower = 1, upper = 50)
),
classif.naiveBayes = makeParamSet(),
classif.glmnet.lasso = makeParamSet(
makeNumericParam("s", lower = -12, upper = 12, trafo = function(x) 2^x)
),
classif.glmnet.ridge = makeParamSet(
makeNumericParam("s", lower = -12, upper = 12, trafo = function(x) 2^x)
),
classif.C50 = makeParamSet(
makeIntegerParam("trials", lower = 1, upper = 100),
makeLogicalParam("winnow")
),
classif.featureless = makeParamSet()
)
learners3 = unlist(lapply(learners2, function(lrn) {
ps = ps[[lrn$id]]
d = length(ps$pars)
# make learner
cl = list(numeric = imputeHist(), factor = imputeConstant("Missing"))
lrn = makeImputeWrapper(lrn, classes = cl, dummy.classes = c("numeric", "factor"))
lrn = makeDummyFeaturesWrapper(lrn)
lrn = makeRemoveConstantFeaturesWrapper(lrn, perc = 0.01, na.ignore = FALSE)
lrn = setPredictType(lrn, predict.type = "prob")
if (d == 0) return(list(lrn))
pars = unique(generateRandomDesign(10*d, ps, trafo = TRUE))
par.list = convertRowsToList(pars, name.vector = TRUE)
if (nrow(pars) > 1)
lrn.list = lapply(par.list, function(x) setHyperPars(lrn, par.vals = x)) else
lrn.list = list(setHyperPars(lrn, par.vals = unlist(unname(par.list), recursive = FALSE)))
}), recursive = FALSE)