R中随机森林的二元部分依赖 [英] Bivariate partial dependence with randomForest in R

查看:56
本文介绍了R中随机森林的二元部分依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含二元因变量和许多预测变量(包括参与者)的数据集.我正在尝试检查不同预测变量对不同参与者的特殊影响.为了做到这一点,我试图查看参与者 id 和其他预测变量之间的交互作用对因变量的影响.我在 R 中使用 randomForest.我可以成功地拟合森林,并且可以为单个变量生成部分依赖图.然而,我需要的是变量对的部分依赖图 - 参与者 + 其他人.这可能吗?

作为参考,我的代码:

data_sample<-data_raw[sample(1:nrow(data_raw),500,replace=F),];test_rf<-randomForest(perceptually.rhotic~vowel+speaker+modified_clip_start+function_word+year_of_birth+gender+fathers_job_type+preausal,data=data_sample,ntree=500,mtry=3);partialPlot(test_rf,pred.dat=data_sample,x.var="speaker");???partialPlot(test_rf,pred.dat=data_sample,x.var=c("speaker","vowel"));

非常感谢任何人可以提供的任何建议!

解决方案

中.

I have a dataset with a binary dependent variable and a number of predictors, including participant. I am trying to examine the idiosyncratic effects of different predictors for different participants. In order to do that, I'm trying to look at the effect of interactions between participant id and the other predictors on the dependent variable. I'm using randomForest in R. I can fit the forest successfully, and can produce partial dependence plots for individual variables. What I need, however, are partial dependence plots for pairs of variables - participant + others. Is this possible?

For reference, my code:

data_sample<-data_raw[sample(1:nrow(data_raw),500,replace=F),];
test_rf<-randomForest(perceptually.rhotic~vowel+speaker+modified_clip_start+function_word+year_of_birth+gender+fathers_job_type+prepausal,data=data_sample,ntree=500,mtry=3);
partialPlot(test_rf,pred.dat=data_sample,x.var="speaker");

??? partialPlot(test_rf,pred.dat=data_sample,x.var=c("speaker","vowel"));

Thanks very much in advance for any advice anyone can offer!

解决方案

The plotmo R package will plot partial dependencies for all variables and pairs of variables (bivariate dependencies) for "any" model. For example:

library(randomForest)
data(trees)
mod <- randomForest(Volume~., data=trees)
library(plotmo)
plotmo(mod, pmethod="partdep") # plot partial dependencies

which gives

You can specify exactly which variable and variable pairs get plotted using plotmo's all1, all2, degree1, and degree2 arguments. Additional examples are in the vignette for the plotmo package.

这篇关于R中随机森林的二元部分依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆