R中的判别分析:如何获得阈值权重

时间:2012-12-29 05:48:12

标签: r

我正在使用R中的2个变量和2个组进行线性判别分析,即

ldares <- lda(dat[,2:3], grouping=dat[,1])

接下来,我想获得分隔组的决策界限的公式。我知道我可以输出线性判别式的系数:

coef(ldares)

但是,鉴于决定界限由:

描述
a*v1 + b*v2 + c = 0,

如何获得偏见阈值权重 c?

2 个答案:

答案 0 :(得分:2)

如果没有给出先前的权重,我相信你会发现c = 0并且判别分数是基于设置先验的案例的分布。您可以看到具有隐式c = 0假设的分数构造使用虹膜数据集生成预测的预测分割:

require(MASS)
ldares <- lda(iris[ iris[,5] %in% c("setosa", "versicolor"),2:3], 
               grouping=iris[iris[,5] %in% c("setosa", "versicolor") ,5])
scores <- with( iris[ iris[,5] %in% c("setosa", "versicolor") , 2:3],
                 cbind(Sepal.Width, Petal.Length) %*% coef(ldares) )
with( iris[ iris[,5] %in% c("setosa", "versicolor") , c(2:3, 5)], 
              plot(Sepal.Width, Petal.Length, col=c("black", "red")[1+(scores>0)])  )

enter image description here

答案 1 :(得分:0)

您应该意识到LDA是居中变量的线性组合。因此,歧视功能确实是:

\Sigma [w * (x - mean(x))]  >  0

因此:

\Sigma [w * x]  >  \Sigma w * mean(x)

因此阈值是\ Sigma w * mean(x)。不幸的是,LDA没有报告整个数据集的平均值(x),只有两组意味着。但这允许我们以相当直观的方式计算阈值。

假设结果是您的LDA结果,则阈值位于对两个类的质心的响应之间的中间位置:

> `sum( result$scaling * result$means[2,] + result$scaling * result$means[1,] )/2`

P.S。请注意,在原始问题w1*a1 + w2*a2 + c = 0中,阈值为-c