【问题标题】:model$importance vs importance(model) in randomForest packagerandomForest 包中的模型$重要性与重要性(模型)
【发布时间】:2019-04-17 13:01:42
【问题描述】:

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

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

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

【问题讨论】:

标签: r random-forest


【解决方案1】:

只需将每个 MeanDecreaseAccuracy 除以 $importanceSD 的对应值

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

here 你可以明白为什么,importance() 通过其 SD 缩放 MeanDecreaseAccuracy

【讨论】:

    猜你喜欢
    • 2020-05-12
    • 2012-07-28
    • 2015-07-25
    • 2020-10-07
    • 2021-04-15
    • 2020-10-27
    • 2021-12-04
    • 2019-09-22
    • 2011-11-18
    相关资源
    最近更新 更多