首页 > 解决方案 > randomForest 包中的模型$重要性与重要性(模型)

问题描述

在使用 r 中的 randomForest 包运行随机森林后,我对访问功能重要性的差异感到有些困惑。使用model$importance 和importance(model) 给出不同的值。有人知道为什么吗?

下面是示例代码。MeanDecreaseAccuracy当我使用rf$importance和时有不同的值importance(rf)

rf = randomForest(Species~., data=iris, importance=T)

rf$importance

                  setosa versicolor  virginica
Sepal.Length 0.028069924 0.02290131 0.02999196
Sepal.Width  0.007430743 0.00234842 0.00802824
Petal.Length 0.340913786 0.31065484 0.30779183
Petal.Width  0.326072508 0.31167317 0.27879456
             MeanDecreaseAccuracy MeanDecreaseGini
Sepal.Length          0.026581478         9.399968
Sepal.Width           0.005823167         2.256985
Petal.Length          0.317224058        43.508494
Petal.Width           0.302483961        44.047933

importance(rf)

                setosa versicolor virginica
Sepal.Length  5.848489   7.437477  6.817425
Sepal.Width   4.584855   1.294841  4.535271
Petal.Length 22.222062  33.130557 28.586522
Petal.Width  21.634934  32.550969 30.980522
             MeanDecreaseAccuracy MeanDecreaseGini
Sepal.Length             9.820337         9.399968
Sepal.Width              5.429112         2.256985
Petal.Length            33.999215        43.508494
Petal.Width             32.807621        44.047933

标签: rrandom-forest

解决方案


只需将每个MeanDecreaseAccuracy除以相应的值即可$importanceSD

rf$importance[, 4]/ rf$importanceSD[,4]
#Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
#10.643412     4.816711    34.096432    32.764032

在这里,您可以看到原因,按其 SD 进行importance()缩放。MeanDecreaseAccuracy


推荐阅读