我正在使用randomForest软件包。为了获得可变的重要性,我使用了意义()函数。我想更改重要性度量的类型。它由“ type”参数确定,该参数有2个可能的值:type = 1或type = 2。这是一个例子:
library(randomForest)
Y = runif(100, 0.0, 1.0)
X1 = runif(100, 0.0, 1.0)
X2 = runif(100, 0.0, 1.0)
rf.model = randomForest::randomForest(Y~X1+X2)
# type 2 : mean decrease in node impurity
imp2 = randomForest::importance(x=rf.model,type=2)
# type 1 : mean decrease in accuracy
imp1 = randomForest::importance(x=rf.model,type=1)
imp2输出:
IncNodePurity
X1 3.130248
X2 3.023091
imp1输出:
X1
X2
您可以看到,type = 2(节点杂质的平均减少)正在运行,但是type = 1(准确性的平均降低)却没有。你知道如何解决这个问题吗?
您必须首先在模型中启用它
rf.model = randomForest::randomForest(Y~X1+X2,importance=T)
然后它将起作用。