【问题标题】:Variable importance plot using randomforest package in R在 R 中使用随机森林包的变量重要性图
【发布时间】:2020-06-06 22:32:42
【问题描述】:

我创建了一个random forest model,现在想查看变量重要性。在尝试这样做时,它只显示MeanDecreaseGini 图,而不是MeanDecreaseAccuracy 图。如果我尝试指定type = 1,它会给出一个错误提示

imp[, i] 中的错误:下标超出范围

type = 2 不会发生同样的情况。

我使用的代码是:

RF_Model<- randomForest(as.factor(Ash )~B1+B2+B3+B4+B5+B6+B7+B8+B9+B10+B11+B12+B13+B14+B15
                        +B16+B17+B18+B19+B20, data=Subset, ntree=2000, Importance=TRUE)
print(RF_Model)
Important=RF_Model$importance
View( Important).

谁能帮我解决这个问题?

【问题讨论】:

    标签: r variables random-forest


    【解决方案1】:

    应该是importance=TRUE 而不是Importance=TRUE。请参阅下面的可重现示例:

    rf = randomForest(Species ~ .,data=iris,Importance=TRUE)
    importance(rf,type=1)
    
    Sepal.Length
    Sepal.Width 
    Petal.Length
    Petal.Width 
    
    rf = randomForest(Species ~ .,data=iris,importance=TRUE)
    importance(rf,type=1)
                 MeanDecreaseAccuracy
    Sepal.Length            10.035280
    Sepal.Width              4.849584
    Petal.Length            32.512948
    Petal.Width             34.386394
    

    【讨论】:

      猜你喜欢
      • 2016-06-24
      • 2017-08-29
      • 1970-01-01
      • 2012-06-10
      • 2015-05-19
      • 2020-11-10
      • 2019-01-30
      • 1970-01-01
      • 2016-09-12
      相关资源
      最近更新 更多