balKfold.xvspec(MLInterfaces)
balKfold.xvspec()所属R语言包:MLInterfaces
generate a partition function for cross-validation, where the partitions are approximately balanced with respect to
产生交叉验证的功能分区,分区约方面的平衡
译者:生物统计家园网 机器人LoveR
描述----------Description----------
generate a partition function for cross-validation, where the partitions are approximately balanced with respect to
产生交叉验证的功能分区,分区约方面的平衡
用法----------Usage----------
balKfold.xvspec(K)
参数----------Arguments----------
参数:K
number of partitions to be computed
分区数量计算
Details
详情----------Details----------
This function returns a closure. The symbol K is bound in the environment of the returned function.
这个函数返回一个关闭。符号K势必在返回的函数的环境。
值----------Value----------
A closure consisting of a function that can be used as a partitionFunc for passage in xvalSpec.
一个功能,可以作为一个partitionFunc通过xvalSpec组成的封闭。
作者(S)----------Author(s)----------
VJ Carey <stvjc@channing.harvard.edu>
举例----------Examples----------
## The function is currently defined as[#函数定义为]
function (K)
function(data, clab, iternum) {
clabs <- data[[clab]]
narr <- nrow(data)
cnames <- unique(clabs)
ilist <- list()
for (i in 1:length(cnames)) ilist[[cnames[i]]] <- which(clabs ==
cnames[i])
clens <- lapply(ilist, length)
nrep <- lapply(clens, function(x) ceiling(x/K))
grpinds <- list()
for (i in 1:length(nrep)) grpinds[[i]] <- rep(1:K, nrep[[i]])[1:clens[[i]]]
(1:narr)[-which(unlist(grpinds) == iternum)]
}
# try it out[尝试一下]
data(crabs)
p1c = balKfold.xvspec(5)
inds = p1c( crabs, "sp", 3 )
table(crabs$sp[inds] )
inds2 = p1c( crabs, "sp", 4 )
table(crabs$sp[inds2] )
allc = 1:200
# are test sets disjoint?[测试集不相交?]
intersect(setdiff(allc,inds), setdiff(allc,inds2))
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|