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