我想在每一行中添加相关的终端节点。 这是我的代码:
library(party)
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, ]
ct <- ctree(V1 ~ ., data = train)
我想分别添加到训练列和测试列(train$TN
和test$TN
),它们将包含每行所在的相关终端。
火车,我尝试过:
train$TN<-factor (ct@where)
并得到:
Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
我尝试过的测试:
test$TN<-predict(ct, test[,V2:V9],type = "node")
并得到:
Error in match.arg(type) : 'arg' should be one of “response”, “prob”