求助各位大神:sample()是不是只能随机抽样一次?我想随机抽样多次、同时对每次抽样结果进行某个特定分析并输出结果,该用哪个函数?

0
已邀请:
0

marxsong 2016-12-14 回答

根据你的问题,可能你是要做重抽样,可以使用 DMwR 包的 bootstrap函数,例如:
data(swiss)

user.rpart <- function(form, train, test, ...) {
require(rpart)
model <- rpart(form, train, ...)
preds <- predict(model, test)
regr.eval(resp(form, test), preds,
stats=c('mae','nmse'), train.y=resp(form, train))
}

## Now the evaluation
eval.res <- bootstrap(learner('user.rpart',pars=list()),
dataset(Infant.Mortality ~ ., swiss),
bootSettings(1234,10)) # bootstrap with 10 repetitions

## Check a summary of the results
summary(eval.res)
这是使用bootstrap重抽样10次来检验rpart模型,评价结果。可以参考一下。

要回复问题请先登录注册