gpt4 book ai didi

r - 下标越界(随机森林的插入符变量重要性)

转载 作者:行者123 更新时间:2023-12-02 05:39:10 24 4
gpt4 key购买 nike

我已经用 R 训练了一个模型:

require(caret)
require(randomForest)
myControl = trainControl(method='cv',number=5,repeats=2,returnResamp='none')
model2 = train(increaseInAssessedLevel~., data=trainData, method = 'rf', trControl=myControl)

数据集相当大,但模型运行良好。我可以访问它的部分并运行命令,例如:

> model2[3]
$results
mtry RMSE Rsquared RMSESD RsquaredSD
1 2 0.1901304 0.3342449 0.004586902 0.05089500
2 61 0.1080164 0.6984240 0.006195397 0.04428158
3 120 0.1084201 0.6954841 0.007119253 0.04362755

但我收到以下错误:

> varImp(model2)
Error in varImp[, "%IncMSE"] : subscript out of bounds

显然应该有一个包装器,但情况似乎并非如此:(参见:http://www.inside-r.org/packages/cran/caret/docs/varImp)

varImp.randomForest(model2)
Error: could not find function "varImp.randomForest"

但这特别奇怪:

> traceback()
No traceback available

> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-redhat-linux-gnu (64-bit)

locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] parallel stats graphics grDevices utils datasets methods
[8] base

other attached packages:
[1] elasticnet_1.1 lars_1.2 klaR_0.6-9 MASS_7.3-26
[5] kernlab_0.9-18 nnet_7.3-6 randomForest_4.6-7 doMC_1.3.0
[9] iterators_1.0.6 caret_5.17-7 reshape2_1.2.2 plyr_1.8
[13] lattice_0.20-15 foreach_1.4.1 cluster_1.14.4

loaded via a namespace (and not attached):
[1] codetools_0.2-8 compiler_3.0.1 grid_3.0.1 stringr_0.6.2
[5] tools_3.0.1

最佳答案

train()语句中,您需要指定选项importance=T。这将传递给底层随机森林调用。否则,不会计算重要性,从而给您带来错误。

关于r - 下标越界(随机森林的插入符变量重要性),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18570568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com