我正在嘗試開發一個模型來預測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。我也檢查了相關性,發現變量之間沒有相關性。我仍然需要計算調整後的蘭特指數,但我想嘗試其他算法,也許有一個返回更好的預測。 –