本文介绍了使用MASS:lda()观察LDA中线性判别式的访问分数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
library(MASS)
example(lda)
plot(z)
如何访问z中的所有点?我想知道LD1和LD2上每个点的值,具体取决于它们的Sp(c,s,v)。
How can I access all the points in z? I want to know the values of every point along LD1 and LD2 depending on their Sp (c,s,v).
推荐答案
您要查找的内容是对象 lda
的对象的 predict()
方法的一部分进行计算(请参见?predict.lda
)。它作为 predict(z)
生成的对象的分量 x
返回:
What you are looking for is computed as part of the predict()
method of objects of class "lda"
(see ?predict.lda
). It is returned as component x
of the object produced by predict(z)
:
## follow example from ?lda
Iris <- data.frame(rbind(iris3[,,1], iris3[,,2], iris3[,,3]),
Sp = rep(c("s","c","v"), rep(50,3)))
set.seed(1) ## remove this line if you want it to be pseudo random
train <- sample(1:150, 75)
table(Iris$Sp[train])
## your answer may differ
## c s v
## 22 23 30
z <- lda(Sp ~ ., Iris, prior = c(1,1,1)/3, subset = train)
## get the whole prediction object
pred <- predict(z)
## show first few sample scores on LDs
head(z$x)
最后一行显示线性判别式中对象分数的前几行
the last line shows the first few rows of the object scores on the linear discriminants
> head(pred$x)
LD1 LD2
40 -8.334664 0.1348578
56 2.462821 -1.5758927
85 2.998319 -0.6648073
134 4.030165 -1.4724530
30 -7.511226 -0.6519301
131 6.779570 -0.8675742
这些得分可以这样绘制
plot(LD2 ~ LD1, data = pred$x)
产生以下情节(针对该训练样本!)
producing the following plot (for this training sample!)
这篇关于使用MASS:lda()观察LDA中线性判别式的访问分数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!