Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
rbind更改列中的值_R_Random Forest - Fatal编程技术网

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新值
应为
新值