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
|
##(1) 定义学习器
learner = lrn("regr.xgboost")
learner$param_set
##(2) 超参数
search_space = ps(
eta = p_dbl(lower=0,upper=1),
gamma = p_dbl(lower=1,upper=5),
max_depth = p_int(lower = 1, upper = 10),
min_child_weight = p_dbl(lower = 1, upper = 10),
subsample = p_dbl(lower = 0.5, upper = 1),
colsample_bytree = p_dbl(lower = 0.5, upper = 1),
nrounds = p_int(lower = 1, upper = 50)
)
design = expand.grid(eta = c(0.01, 0.1, 0.5),
gamma = c(1, 3),
max_depth=c(4, 8),
min_child_weight = c(3, 6),
subsample = c(0.6, 0.9),
colsample_bytree = c(0.6, 0.9),
nrounds = c(10, 20),
stringsAsFactors = F) %>% as.data.table()
##(3) 交叉验证
resampling = rsmp("cv")
measure = msr("regr.mse")
|