R ranger 包中的预测概率 [英] Predicted probabilities in R ranger package

查看:238
本文介绍了R ranger 包中的预测概率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用随机森林分类在 R 中构建模型.(通过 Ned Horning 编辑代码)我首先使用了 randomForest 包,但后来发现了 ranger,它保证了更快的计算.

I am trying to build a model in R with random forest classification. (By editing the code by Ned Horning) I first used randomForest package but then found ranger, which promises faster calculations.

起初,我使用下面的代码在用 randomForest 拟合模型后得到每个类的预测概率:

At first, I used the code below to get predicted probabilities for each class after fitting the model with randomForest as:

predProbs <- as.data.frame(predict(randfor, imageBlock, type='prob'))

这里的概率类型如下:

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

ranger 中,我意识到没有 type = 'prob' 选项.

In ranger, I realized that there is no type = 'prob' option.

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

I searched and tried some adjustments but couldn't get any progress. I need an object or so containing probabilities as mentioned above with ranger package.

有人可以就这个问题提供一些建议吗?

Could anyone give some advice about the issue?

推荐答案

你需要训练一个概率分类器"类型的 ranger 对象:

You need to train a "probabilistic classifier"-type ranger object:

library("ranger")
iris.ranger = ranger(Species ~ ., data = iris, probability = TRUE)

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

This object computes a matrix (n_samples, n_classes) when used in the predict.ranger function:

probabilities = predict(iris.ranger, data = iris)$predictions

这篇关于R ranger 包中的预测概率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆