0
我有data.frame TC
,有17744个观察值的13个变量。最后一个变量是目标:a Factor w/ 2 levels "0", "1"
。randomForest没有预测连续样本
我做的:
n.col <- ncol(TC)
x.train.or <- TC[1:12000, -n.col]
y.train.or <- TC[1:12000, n.col]
x.test.or <- TC[12000:17000, -n.col]
y.test.or <- TC[12000:17000, n.col]
rf.or <- randomForest(y=y.train.or, x=x.train.or, ntree=500, mtry=5,
importance=TRUE, keep.forest=TRUE,
na.action=na.roughfix, replace=FALSE)
pr.or <- predict(rf.or, x.test.or)
table(y.test.or, pr.or, dnn=c("Actual", "Predicted"))
# Predicted
# Actual 0 1
# 0 2424 780
# 1 1056 741
非常坏的结果。
然后我重复这个模型进行随机抽样配件:
set.seed <- 123
t.t <- holdout(TC[, n.col], ratio=3/5, mode = "random")
x.train.r <- TC[t.t$tr, - (n.col)]
y.train.r <- TC[t.t$tr, (n.col)]
x.test.r <- TC[t.t$ts, - (n.col)]
rf.r <- randomForest(y=y.train.r, x=x.train.r, ntree=500, mtry=5,
importance=TRUE, keep.forest=TRUE,
na.action=na.roughfix, replace=FALSE)
pr.r <- predict(rf.r, x.test.r)
table(y.test.r, pr.r, dnn=c("Actual", "Predicted"))
# Predicted
# Actual 0 1
# 0 4274 215
# 1 353 2257
很不错的成绩,但取决于形成的一个数据集合的样本的一种方式。 我解决的问题只是假定连续采样。
请帮帮我!
答案的问题: (1)当然,我这样做:
library(randomForest)
library(rminer)
(3)我重复使用:
n.col <- ncol(TC)
x.train.or <- TC[1:12000, -n.col]
y.train.or <- TC[1:12000, n.col]
x.test.or <- TC[12001:17000, -n.col]
y.test.or <- TC[12001:17000, n.col]
和接收相同的可怕结果
Predicted
Actual 0 1
0 2413 790
1 1049 748
(4)可能有问题吗?一些变量在[1:17000]上是随机的,但在[1:100]上不是随机的(我没有图纸的权利) 。
在这种情况下该做什么?
什么是你的问题?几点意见:(1)请包括'library'调用(即'library(randomForest)'和'library(rminer)')。 (2)你没有包含你如何创建'y.test.r'的代码(虽然很明显它应该如何创建。)(3)我假设你不打算在你的测试数据集中包含obs。12000 (4)“TC”行的顺序可能不是随机的(即前12000个obs的'y'和'x'之间的关系并不代表下一个5000 obs)。 – jbaums 2014-10-05 11:11:09
我纠正了一个问题 – faa1947 2014-10-06 13:35:10