我正在尝试开发一个模型来预测WaitingTime变量。我在以下数据集上运行随机森林。随机森林的高OOB错误率
$ BookingId : Factor w/ 589855 levels "00002100-1E20-E411-BEB6-0050568C445E",..: 223781 471484 372126 141550 246376 512394 566217 38486 560536 485266 ...
$ PickupLocality : int 1 67 77 -1 33 69 67 67 67 67 ...
$ ExZone : int 0 0 0 0 1 1 0 0 0 0 ...
$ BookingSource : int 2 2 2 2 2 2 7 7 7 7 ...
$ StarCustomer : int 1 1 1 1 1 1 1 1 1 1 ...
$ PickupZone : int 24 0 0 0 6 11 0 0 0 0 ...
$ ScheduledStart_Day : int 14 20 22 24 24 24 31 31 31 31 ...
$ ScheduledStart_Month : int 6 6 6 6 6 6 7 7 7 7 ...
$ ScheduledStart_Hour : int 14 17 7 2 8 8 1 2 2 2 ...
$ ScheduledStart_Minute : int 6 0 58 55 53 54 54 0 12 19 ...
$ ScheduledStart_WeekDay: int 1 7 2 4 4 4 6 6 6 6 ...
$ Season : int 1 1 1 1 1 1 1 1 1 1 ...
$ Pax : int 1 3 2 4 2 2 2 4 1 4 ...
$ WaitingTime : int 45 10 25 5 15 25 40 15 40 30 ...
我使用的样品的方法拆分成数据集训练/测试子集中到80%/ 20%,然后运行一个随机森林排除BookingId因素。这仅用于验证预测。
set.seed(1)
index <- sample(1:nrow(data),round(0.8*nrow(data)))
train <- data[index,]
test <- data[-index,]
library(randomForest)
extractFeatures <- function(data) {
features <- c( "PickupLocality",
"BookingSource",
"StarCustomer",
"ScheduledStart_Month",
"ScheduledStart_Day",
"ScheduledStart_WeekDay",
"ScheduledStart_Hour",
"Season",
"Pax")
fea <- data[,features]
return(fea)
}
rf <- randomForest(extractFeatures(train), as.factor(train$WaitingTime), ntree=600, mtry=2, importance=TRUE)
问题是,尝试降低OOB错误率并提高准确性的所有尝试均失败。我设法达到的最大准确度是〜23%。
我试图改变使用的功能的数量,不同的ntree和mtry的值,不同的训练/测试比率,也考虑只有WaitingTime < = 40的数据。我最后的尝试是遵循MrFlick的建议并获得所有类别的相同样本量为我的预测变量(WaitingTime)的所有类别获得相同的样本量。 1
tempdata <- subset(tempdata, WaitingTime <= 40)
rndid <- with(tempdata, ave(tempdata$Season, tempdata$WaitingTime, FUN=function(x) {sample.int(length(x))}))
data <- tempdata[rndid<=27780,]
你知道的任何其他方式怎么我至少可以精度在50%以上实现?
记录由WaitingTime类:提前
谢谢!
谢谢你的回答thc。将跟随你的领导和回复。 –
嗨th, 我对我的数据集进行了简单的回归,得到了一个145.1712的sme。我也检查了相关性,发现变量之间没有相关性。我仍然需要计算调整后的兰特指数,但我想尝试其他算法,也许有一个返回更好的预测。 –