我想获得Optional.empty
的终端节点。我基于以下question
randomforets
我得到的最后一行:
require(randomForest)
require(party)
require (data.table)
dat1 <- fread('https://archive.ics.uci.edu/ml/machine-learning-databases/abalone/abalone.data',stringsAsFactors=T)
## split data to train and test
set.seed(123)
dat1 <- subset(dat1, !is.na(V1))
smp_size<-100
train_ind <- sample(seq_len(nrow(dat1)), size = smp_size)
train <- dat1[train_ind, ]
test <- dat1[-train_ind, ]
#dat1$V1<-as.factor(dat1$V1)
rf <- randomForest(V1 ~ ., data = train, ntree = 10, keep.inbag = TRUE)
predList <- lapply(seq_len(rf$ntree), function(z)
predict(rf, newdata = train[rf$inbag[, z] == 1, ], nodes = TRUE))
node.list <- lapply(seq_len(rf$ntree), function(z)
split(x = train[rf$inbag[, z] == 1, "x"],
f = attr(predList[[z]], "nodes")[, z]))