【发布时间】:2018-09-28 07:20:38
【问题描述】:
我正在使用可选参数 caseweights 拟合 cforest,它是一个双矩阵,其中 ncol(caseweights)== 我的随机森林中的树数和 nrow(caseweights)= 观察数。此外,我正在对它们进行规范化,以使 colSums 等于 1。但是,当我想将我的 OOB 预测与真实响应进行比较时,我总是会收到以下错误:
RET@prediction_weights 中的错误(newdata = newdata,mincriterion = mincriterion, : 无法计算袋外预测 观察号 1
我在 github 上查了 C 源代码,但找不到为什么它不起作用。
(如果我使用“标准”权重,即长度 == 观察次数的向量,仅用于采样,也会出现同样的错误)
我做错了什么?
这是一个可重现的例子:
install.packages('party')
require('party')
head(iris)
weights<-rep(1,nrow(iris))
weights[iris$Species=='virginica']<-2
#normalize
weights<-weights/sum(weights)
ntree<-100
#generate double matrix of caseweights
caseweights<-matrix(rep(weights,ntree),ncol=ntree)
colSums(caseweights)
#fit forest
f <- cforest(Species ~ ., data = iris,controls = cforest_unbiased(ntree=ntree,mtry=3,trace=TRUE),weights=caseweights)
#check out of bag cross classification
table(iris$Species,Predict(f,OOB=TRUE)) #throws error
非常感谢您的帮助。
【问题讨论】:
-
非常感谢 Torsten,我今天在拟合后提取权重时认出了它。最好的
标签: random-forest prediction party