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
|
test_that("regr_glmboost", {
requirePackagesOrSkip("mboost", default.method = "load")
parset.list1 = list(
list(family = mboost::Gaussian(),
control = mboost::boost_control(nu = 0.03)),
list(family = mboost::GammaReg(nuirange = c(0, 50)),
control = mboost::boost_control(mstop = 50), center = TRUE),
list(family = mboost::Family(ngradient = function(y, f, w = 1) y - f,
loss = function(y, f) (y - f)^2,
name = "My Gauss Variant"))
)
parset.list2 = list(
list(family = "Gaussian", nu = 0.03),
list(family = "GammaReg", nuirange = c(0, 50), mstop = 50, center = TRUE),
list(family = "custom.family",
custom.family.definition = mboost::Family(ngradient = function(y, f,
w = 1) {
y - f
},
loss = function(y, f) (y - f)^2,
name = "My Gauss Variant"))
)
old.predicts.list = list()
for (i in seq_along(parset.list1)) {
parset = parset.list1[[i]]
pars = list(regr.formula, data = regr.train)
pars = c(pars, parset)
m = do.call(mboost::glmboost, pars)
old.predicts.list[[i]] = as.vector(predict(m, newdata = regr.test))
}
testSimpleParsets("regr.glmboost", regr.df, regr.target, regr.train.inds,
old.predicts.list, parset.list2)
})
test_that("regr_glmboost works with families for count data", {
# set some dummy counts
new.regr.df = regr.df
new.regr.df[, regr.target] = as.integer(floor(new.regr.df[, regr.target]))
new.regr.train = new.regr.df[regr.train.inds, ]
new.regr.test = new.regr.df[regr.test.inds, ]
parset.list1 = list(
list(family = mboost::Poisson(), control = mboost::boost_control(nu = 0.02)),
list(family = mboost::NBinomial()),
list(family = mboost::Hurdle())
)
parset.list2 = list(
list(family = "Poisson", nu = 0.02),
list(family = "NBinomial"),
list(family = "Hurdle")
)
old.predicts.list = list()
for (i in seq_along(parset.list1)) {
parset = parset.list1[[i]]
pars = list(regr.formula, data = new.regr.train)
pars = c(pars, parset)
m = do.call(mboost::glmboost, pars)
old.predicts.list[[i]] = as.vector(predict(m, newdata = new.regr.test))
}
testSimpleParsets("regr.glmboost", new.regr.df, regr.target, regr.train.inds,
old.predicts.list, parset.list2)
})
|