rbind更改列中的值
因此,我试图从rbind更改列中的值,r,random-forest,R,Random Forest,因此,我试图从randomForest对象中提取所有树数据,并将其放入数据帧中。我一次拉出一棵树,cbinding它与该树的索引,并尝试rbind。这是我的密码。应易于复制 # Do some setup, and train a basic random forest model library(randomForest) data(iris) model <- randomForest(Species ~ ., data=iris) # Make a data frame con
randomForest
对象中提取所有树数据,并将其放入数据帧中。我一次拉出一棵树,cbind
ing它与该树的索引,并尝试rbind
。这是我的密码。应易于复制
# Do some setup, and train a basic random forest model
library(randomForest)
data(iris)
model <- randomForest(Species ~ ., data=iris)
# Make a data frame containing all the tree data
output <- data.frame()
for (i in 1:model[['forest']][['ntree']]) {
new_values <- getTree(model, i)
new_values <- cbind(tree = rep(i, nrow(new_values)), new_values)
output <- rbind(output, test_new, make.row.names = FALSE)
# Added for debug purposes...
new_values
output
break
}
#进行一些设置,并训练一个基本的随机林模型
图书馆(森林)
数据(iris)
模型您刚刚通过test\u new
在rbind
内部交换了new\u值。我更改了它并尝试了下面的代码,可以获得包含所有树数据的数据帧,并根据树编号:
# Do some setup, and train a basic random forest model
library(randomForest)
data(iris)
model <- randomForest(Species ~ ., data=iris)
# Make a data frame containing all the tree data
output <- data.frame()
for (i in 1:model[['forest']][['ntree']]) {
new_values <- getTree(model, i)
new_values <- cbind(tree = rep(i, nrow(new_values)), new_values)
output <- rbind(output, new_values, make.row.names = FALSE)
}
#进行一些设置,并训练一个基本的随机林模型
图书馆(森林)
数据(iris)
模型测试\u新值
应为新值
?