簡體   English   中英

變量重要性 plot 在 R 中使用隨機森林 package

[英]Variable importance plot using randomforest package in R

我創建了一個random forest model現在想看看變量的重要性。 在嘗試這樣做時,它只顯示MeanDecreaseGini plot,而不是MeanDecreaseAccuracy plot。如果我嘗試指定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).

誰能幫我解決這個問題?

它應該是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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM