Journal of Advanced Transportation / 2018 / Article / Alg 1

Research Article

Random Forests-Based Operational Status Perception Model in Extra-Long Highway Tunnels with Longitudinal Ventilation: A Case Study in China

Algorithm 1

# division of training set and test set
set.seed(100)
ind <- sample(2, nrow(Mydataset), replace = TRUE, prob = c(0.7,0.3))
trainingset <- Mydatasetind==1, # training set accounts for 70%
testset <- Mydatasetind==2, # test set accounts for 30%
# combined parameters in Random Forests
library(randomForest)
library(caret)
M <- ncol(trainingset)
ntree <- 10c(1:50)
result <- data.frame()
# model training
set.seed(100)
for(m in 1:(M-1))
for(n in ntree)
fit.rf <- randomForest(Status ~., data = trainingset, mtry = m, ntree = n, na.action = na.omit)
OOB.ER <- 1-confusionMatrix(as.table(fit.rf$confusion[,c(-4)]))overall[Accuracy]
result <- rbind(result, data.frame(m, n, OOB.ER))
print(result)