随机森林的ROC曲线使用R中的pROC拟合对象,以使用正或负“投票”作为预测器

问题描述 投票:1回答:1

肥胖是二元反应变量,1表示肥胖,0表示不肥胖。体重是一个连续的预测因子。

使用RF对肥胖进行分类:

library(randomFores)

rf <- randomForest(factor(obese)~weight)

给我们一个适合的对象包含:

> summary(rf)
                Length Class  Mode     
call               2   -none- call     
type               1   -none- character
predicted        100   factor numeric  
err.rate        1500   -none- numeric  
confusion          6   -none- numeric  
votes            200   matrix numeric  
oob.times        100   -none- numeric  
classes            2   -none- character
importance         1   -none- numeric  
importanceSD       0   -none- NULL     
localImportance    0   -none- NULL     
proximity          0   -none- NULL     
ntree              1   -none- numeric  
mtry               1   -none- numeric  
forest            14   -none- list     
y                100   factor numeric  
test               0   -none- NULL     
inbag              0   -none- NULL     
terms              3   terms  call  

我相信投票矩阵显示有多少票,从0到1,rF将每个案例分类为任一类;不肥胖= 0,肥胖= 1:

> head(rf$votes, 20) 
           0          1
1  0.9318182 0.06818182
2  0.9325843 0.06741573
3  0.2784091 0.72159091
4  0.9040404 0.09595960
5  0.3865979 0.61340206
6  0.9689119 0.03108808
7  0.8187135 0.18128655
8  0.7170732 0.28292683
9  0.6931217 0.30687831
10 0.9831461 0.01685393
11 0.3425414 0.65745856
12 1.0000000 0.00000000
13 0.9728261 0.02717391
14 0.9848485 0.01515152
15 0.8783069 0.12169312
16 0.8553459 0.14465409
17 1.0000000 0.00000000
18 0.3389831 0.66101695
19 0.9316770 0.06832298
20 0.9435897 0.05641026

拿那些:

votes_2 <- rf$votes[,2]
votes_1 <- rf$votes[,1]

我的问题是为什么:

pROC::plot.roc(obese, votes_1)

pROC::plot.roc(obese, votes_2)

产生相同的结果。

r random-forest roc proc-r-package
1个回答
0
投票

首先要意识到的是,ROC分析并不关心数据的确切值。相反,它会查看数据点的排名以及排名如何分开。

其次,正如上面评论中所提到的,0级和1级的投票在每次观察中总计为1。这意味着在排名方面,两者是等价的(以排序方向为模)。

最后一个难题是pROC并不假设您将预测变量作为属于正类的概率。相反,您可以传递任何类型的分数,并自动检测比较的方向。默认情况下这是静默完成的,但您可以通过将quiet标志设置为FALSE来查看会发生什么:

> pROC::roc(obese, votes_1, quiet = FALSE)
Setting levels: control = 0, case = 1
Setting direction: controls < cases

> pROC::roc(obese, votes_2, quiet = FALSE)
Setting levels: control = 0, case = 1
Setting direction: controls > cases

请注意,在votes_2的情况下,它检测到负类具有更高的值(基于中位数)并相应地设置比较的方向。

如果这不是您想要的,您可以始终明确设置类级别和方向参数:

> pROC::roc(obese, votes_2, levels = c(0, 1), direction = "<")

这将导致“反转”曲线显示votes_2在检测具有较高值的​​阳性类时如何表现比随机差。

© www.soinside.com 2019 - 2024. All rights reserved.