随机森林参考

机器算法验证 参考 特征选择 随机森林 模型选择 博鲁塔
2022-03-28 23:30:15

我想了解Boruta 包是如何工作的。您能否为所谓的随机森林的理论方面推荐一些参考资料?

下面是两个说明性示例,说明为什么我会被 Boruta 算法所吸引。

第一个例子

> set.seed(666)
> # simulates data
> # y does not depend on x4
> # y depends on x1, x2, x3 only through x3
> x1 <- rnorm(50); x2 <- rnorm(50) ; x3 <- (x1+x2)^2; x4 <- rnorm(50)
> y <- x3+rnorm(50,0.1)
>
> # lm() only indicates x3 is "important"
> summary(lm(y~x1+x2+x3+x4))

Call:
lm(formula = y ~ x1 + x2 + x3 + x4)

Residuals:
    Min      1Q  Median      3Q     Max 
-3.0000 -0.7137  0.0352  0.7082  1.7918 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   0.1875     0.1874   1.000    0.323    
x1           -0.1541     0.1469  -1.049    0.300    
x2            0.1153     0.1949   0.591    0.557    
x3            0.9097     0.0501  18.160   <2e-16 ***
x4            0.1263     0.1518   0.832    0.410    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 1.123 on 45 degrees of freedom
Multiple R-squared: 0.9013,     Adjusted R-squared: 0.8925 
F-statistic: 102.7 on 4 and 45 DF,  p-value: < 2.2e-16 

> # Boruta indicates x1, x2, x3 are important
> Boruta(y~x1+x2+x3+x4, maxRuns=500)
Boruta performed 174 randomForest runs in 10.409 secs.
        3 attributes confirmed important: x1 x2 x3
        1 attributes confirmed unimportant: x4

第二个例子

> set.seed(421)
> # simulates data
> # y does not depend on u1
> # y does not depend on u2
> # but y depends on u1+u2
> nsims <- 100
> u1 <- runif(nsims)
> u2 <- runif(nsims)
> x <- (u1+u2)-floor(u1+u2)
> y <- rnorm(nsims, x,.05)
> 
> # lm() does not detect some dependence
> summary(fit <- lm(y~u1))

Call:
lm(formula = y ~ u1)

Residuals:
    Min      1Q  Median      3Q     Max 
-0.5411 -0.2234  0.0005  0.2197  0.4901 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.55721    0.05902   9.442 1.97e-15 ***
u1          -0.07858    0.09714  -0.809    0.421    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.2668 on 98 degrees of freedom
Multiple R-squared: 0.006633,   Adjusted R-squared: -0.003503 
F-statistic: 0.6544 on 1 and 98 DF,  p-value: 0.4205 

> summary(fit <- lm(y~u2))

Call:
lm(formula = y ~ u2)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.53996 -0.21855  0.01298  0.22406  0.49940 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.47022    0.05124   9.178 7.38e-15 ***
u2           0.09435    0.09298   1.015    0.313    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.2663 on 98 degrees of freedom
Multiple R-squared: 0.0104,     Adjusted R-squared: 0.000299 
F-statistic:  1.03 on 1 and 98 DF,  p-value: 0.3127 

> summary(fit <- lm(y~u1+u2))

Call:
lm(formula = y ~ u1 + u2)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.53400 -0.22071  0.00699  0.21612  0.54375 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.51609    0.06840   7.545 2.45e-11 ***
u1          -0.09978    0.09859  -1.012    0.314    
u2           0.11176    0.09455   1.182    0.240    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.2663 on 97 degrees of freedom
Multiple R-squared: 0.02074,    Adjusted R-squared: 0.0005478 
F-statistic: 1.027 on 2 and 97 DF,  p-value: 0.3619 

> 
> # Boruta() does
> Boruta(y~u1)
Boruta performed 44 randomForest runs in 6.328125 secs.
        No attributes has been deemed important
        1 attributes confirmed unimportant: u1
> Boruta(y~u2)
Boruta performed 20 randomForest runs in 2.8125 secs.
        No attributes has been deemed important
        1 attributes confirmed unimportant: u2
> Boruta(y~u1+u2)
Boruta performed 48 randomForest runs in 6.796875 secs.
        2 attributes confirmed important: u1 u2
        No attributes has been deemed unimportant
1个回答

随机森林是 Breiman 在这篇论文中提出的一种机器学习算法(也有关于它的网页)。它的重要特性是它可以计算属性的重要性度量,以显示它们对模型的有用程度——它通常比与决策或线性模型系数显着性的相关性更好,因为它可以处理一些非线性和多属性交互而无需用过度拟合或组合爆炸来炸毁屋顶,但显然远非完美地重建底层的贝叶斯网络。

现在,该度量作为特征排名非常有效,但它不是两个特征选择问题的完整答案 - 需要一些截止值来选择最小最优(即模型效果最佳的属性集)和所有相关集(即客观上与决策相关的属性集)。

最小最优问题通常很容易,可以通过递归特征消除或(甚至更好)一些支持正则化的算法来完成。

另一方面,所有相关问题都非常讨厌,通常需要一些显式或隐式对比属性来获得重要性阈值以及重要性度量的一些稳定性和“鲁棒化”——Boruta 是试图通过以下方式做到这一点的 RF 包装算法之一使用人工随机属性扩展数据集并迭代 RF 训练,逐步清除声称不重要的属性。

注意:当然有非基于 RF 的方法来处理这两个特征选择问题,或者使用其他重要性源,将特征选择添加到模型的内部优化中,或者只是在属性和决策之间执行一些或多或少复杂的相关性测试。有关此主题的更多内容,您可以浏览此预印本
对于特征选择的两个问题-Bayes-net 视觉,请参阅本文