R游侠包中的预测概率

Bat*_*lak 2 r random-forest

我正在尝试使用随机森林分类在R中建立模型。(通过由奈德霍宁编辑代码)予先用随机森林包,但随后发现测距仪包,其中承诺更快的计算。

首先,我使用下面的代码来获取模型末尾每个类的预测概率:

predProbs <- as.data.frame(predict(randfor, imageBlock, type='prob'))
Run Code Online (Sandbox Code Playgroud)

这里的概率类型如下:

我们的模型中有500棵树,其中250棵表示观察为1类,因此概率为250/500 = 50%

Ranger中,我意识到没有type = 'prob'选择。

我搜索并尝试了一些调整,但没有任何进展。我需要一个包含上述Ranger软件包中所述概率的对象。

有人可以给这个问题一些建议吗?

use*_*924 5

您需要训练“概率分类器”类型的ranger对象:

library("ranger")
iris.ranger = ranger(Species ~ ., data = iris, probability = TRUE)
Run Code Online (Sandbox Code Playgroud)

predict.ranger函数中使用此对象时,将计算一个矩阵(n_samples,n_classes):

probabilities = predict(iris.ranger, data = iris)$predictions
Run Code Online (Sandbox Code Playgroud)