如何在R中的插入符号模型中使用ggRandomForests依赖图?

问题描述 投票:0回答:2

我想使用gg_variable包中的ggRandomForests函数为我的模型创建部分依赖图的一个方面。我有以下内容,但不起作用。

我该怎么做?

library("caret")
library("ggRandomForests")
library("randomForest") 
data("iris")
iris$Species<-NULL
control = trainControl(method="cv", number=5,savePredictions = TRUE)  
in_train= createDataPartition(iris$Sepal.Length, p=.66, list=FALSE) 
train_st=iris[in_train,]
test_st=iris[-in_train,] 
trf_sep = train(Sepal.Length ~ .,
          data=train_st,ntree=800,method="rf",metric="Rsquared",trControl=control,importance = TRUE)
gg_variable(trf_sep)#Here is the problem
r plot regression r-caret
2个回答
0
投票

gg_variable要求从randomForest模型输出。它不适用于caret::train功能的输出。在这种情况下,您可以使用train程序包中的caret函数来调整mtry并使用带有调整后的mtry的randomForest程序包来拟合随机森林模型,然后在[like]上应用gg_variable

library("caret")
library("ggRandomForests")
library("randomForest") 
data("iris")
iris$Species<-NULL
control = trainControl(method="cv", number=5,savePredictions = TRUE)  
in_train= createDataPartition(iris$Sepal.Length, p=.66, list=FALSE) 
train_st=iris[in_train,]
test_st=iris[-in_train,] 
trf_sep = train(Sepal.Length ~ .,
                data=train_st,ntree=800,method="rf",metric="Rsquared",trControl=control,importance = TRUE)
try <- randomForest(Sepal.Length ~ .,
             data=train_st,ntree=800, mtry=3)


gg_dta <- gg_variable(try)
plot(gg_dta, xvar="Sepal.Width")

0
投票

最终模型存储在train对象中,并且属于RandomForest类。除非它没有调用整个数据集。

© www.soinside.com 2019 - 2024. All rights reserved.