R中的Randomforest在split.default中的错误...第一个参数必须是向量...对于终端节点

时间:2018-11-28 17:09:18

标签: r nodes random-forest

我想获得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]))

0 个答案:

没有答案