2016-10-03 143 views
0

this question,我想知道是否有可能提取二次判别分析(QDA)的分数,并在像PCA分数后重用它们。如何绘制质量:qda分数

## 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 

使用QDA这里

z <- qda(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(pred$x) 
# NULL 
plot(LD2 ~ LD1, data = pred$x) 
# Error in eval(expr, envir, enclos) : object 'LD2' not found 
+0

这就是为什么我问这个问题,我不知道在哪里或如何获得通常存储在'predict'函数'x'中的分数。 –

+0

'predict.qda'_clearly__states_返回'class'(MAP分类)和'posterior'(类别的后验概率)的帮助。 – hrbrmstr

+0

是的,但我想知道排序分数在哪里... –

回答

0

注意:太长/格式化的评论。不是答案

您可能希望尝试rrcov包:

library(rrcov) 

z <- QdaCov(Sp ~ ., Iris[train,], prior = c(1,1,1)/3) 
pred <- predict(z) 
str(pred) 
## Formal class 'PredictQda' [package "rrcov"] with 4 slots 
## [email protected] classification: Factor w/ 3 levels "c","s","v": 2 2 2 1 3 2 2 1 3 2 ... 
## [email protected] posterior  : num [1:41, 1:3] 5.84e-45 5.28e-50 1.16e-25 1.00 1.48e-03 ... 
## [email protected] x    : num [1:41, 1:3] -97.15 -109.44 -54.03 2.9 -3.37 ... 
## [email protected] ct   : 'table' int [1:3, 1:3] 13 0 1 0 16 0 0 0 11 
## .. ..- attr(*, "dimnames")=List of 2 
## .. .. ..$ Actual : chr [1:3] "c" "s" "v" 
## .. .. ..$ Predicted: chr [1:3] "c" "s" "v" 

它还具有强大的PCA方法可能是有用的。不幸的是,并不是R中的每个模型都符合相同的对象结构/ API,并且这不会是线性模型,因此它不太可能符合线性模型拟合结构API。

有怎样直观这里QDA结果的例子 - http://ramhiser.com/2013/07/02/a-brief-look-at-mixture-discriminant-analysis/

而且,你可以这样做:

library(klaR) 

partimat(Sp ~ ., data=Iris, method="qda", subset=train) 

enter image description here

为QDA结果的分区图。

+0

当使用你的例子,我有这个错误:'solve.default(getCov(mcd))中的错误: 系统是计算奇异的:互惠条件数= 3.75922e -17此外:警告消息:在covMcd(x = x,raw.only = raw.only,alpha = alpha,nsamp = nsamp,: 变量4的绝对偏差的15阶统计量为零。 对于(m_1,...,p_(x_ip_m_p)= 0,方程a_1 *(x_i1_m_1)+ ... + a_p *(x_ip_m_p)= 0时,有15个观测值(在26个观测的整个数据集中) m_p)这些观测值的平均值和来自矢量a < - c(0,0,0,1)的系数a_i' –

+0

此外,'klaR'图不显示排序空间,但是性状值的二元组合 –

+0

我是否必须得出结论:LDA分数和QDA分数是相同的? –