【发布时间】:2015-05-20 11:02:25
【问题描述】:
当我在 R 中对数据集执行预测时,出现以下错误:
Mode.rf <- randomForest(trX,trYc,ntree=1000,proximity=TRUE)
trts = rbind(trX,ts)
Plu.pred <- predict(Mode.rf,trts,proximity=TRUE)
predict.randomForest 中的错误(Mode.rf,trts,proximity = TRUE): newdata 中缺少训练数据中的变量
以下细节描述了前几个样本的数据。
trts #In total, 1376 observations out of 95 variables
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21
1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0
2 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0
Mode.rf
# Call:
# randomForest(x = trX, y = trYc, ntree = 1000, proximity = TRUE)
# Type of random forest: classification
# Number of trees: 1000
# No. of variables tried at each split: 9
# OOB estimate of error rate: 80.29%
# Confusion matrix:
# 1 2 3 4 class.error
# 1 74 85 129 99 0.8087855
# 2 106 84 105 58 0.7620397
# 3 125 90 51 76 0.8508772
# 4 114 45 72 62 0.7883959
有人可以帮我解决这个问题吗?
【问题讨论】:
-
您的
ts数据中可能有不在trX中的类。
标签: r random-forest missing-data