r - randomForest did not predict serial samples -
r - randomForest did not predict serial samples -
i have data.frame tc
, 17744 observations of 13 variables. lastly variable target: factor w/ 2 levels "0", "1"
.
i do:
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
very bad result.
then repeat model fitting random sample:
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
very result depended on way of formation of sample of 1 info set. problem solves assumed serial sample.
please, help me!
answer questions: (1)certainly do:
library(randomforest) library(rminer)
(3) repeat with:
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]
and receiving same awful result
predicted actual 0 1 0 2413 790 1 1049 748
(4)there problem in it? variables random on [1:17000], not random on [1:100] (i had no rights drawings).
what in case?
first, it's going little hard reply without knowing state of data. can including test set in train set if observations repeat in sort of manner.
one of best ways validate results through using sort of cross-validation technique paying heed making sure separate test , train set. below video watch on that.
http://vimeo.com/75432414
r random-forest
Comments
Post a Comment