绘制线性判别分析结果

时间:2014-12-30 00:15:57

标签: r

我有一个数据集,我已经执行了LDA。我的数据集只包含2个类,我在网上看到了很多例子,其中有3个类,并且在这些例子中创建了一个图,使用ggplot甚至只是绘图函数。据我所知,这些图通常使用通过执行lda函数生成的LD1和LD2。

然而,由于我只有2个类,当我运行lda时,我只获得LD1,所以我想知道如何在我的情况下进行绘图,即我是否还能以某种方式创建散点类图?

我正在使用来自https://archive.ics.uci.edu/ml/datasets/Statlog+%28German+Credit+Data%29

的一些德国信用数据

我的代码是

library(MASS)
data1<-read.csv("germancredit1.csv")
head(data1)

train <- 1:700
#Perform LDA
lda <- lda(GoodCredit ~ ., data=data1[train,])
lda.p <- predict(lda, newdata=data1[-train,])$class

和lda产生以下内容。

> lda
Call:
lda(GoodCredit ~ ., data = data1[train, ])

Prior probabilities of groups:
        B         G 
0.2957143 0.7042857 

Group means:
  checkingstatus1A12 checkingstatus1A13 checkingstatus1A14 duration2 history3A31 history3A32 history3A33 history3A34
B          0.3961353         0.04830918          0.1497585  24.56522  0.08695652   0.5555556  0.10628019   0.1690821
G          0.2332657         0.07505071          0.4908722  19.01014  0.02434077   0.5294118  0.08924949   0.3346856
  purpose4A41 purpose4A410 purpose4A42 purpose4A43 purpose4A44 purpose4A45 purpose4A46 purpose4A48 purpose4A49  amount5
B  0.04347826   0.01932367   0.1980676   0.2173913  0.01449275  0.02898551  0.07246377 0.004830918  0.11111111 3802.048
G  0.11359026   0.01217039   0.1825558   0.3083164  0.01014199  0.02231237  0.05070994 0.012170385  0.09127789 2922.126
  savings6A62 savings6A63 savings6A64 savings6A65 employ7A72 employ7A73 employ7A74 employ7A75 installment8 status9A92
B   0.1304348  0.02898551  0.01932367   0.1207729  0.2270531  0.3478261  0.1256039  0.2077295     3.096618  0.3623188
G   0.1014199  0.07302231  0.06085193   0.1926978  0.1440162  0.3488844  0.2028398  0.2535497     2.920892  0.2860041
  status9A93 status9A94 others10A102 others10A103 residence11 property12A122 property12A123 property12A124   age13
B  0.4637681 0.09661836   0.06763285   0.03381643    2.797101      0.2222222      0.3526570      0.2125604 34.0000
G  0.5882353 0.08924949   0.03245436   0.06085193    2.813387      0.2190669      0.3346856      0.1318458 35.8783
  otherplans14A142 otherplans14A143 housing15A152 housing15A153  cards16 job17A172 job17A173 job17A174 liable18
B       0.07246377        0.7391304     0.6570048    0.14009662 1.371981 0.1835749 0.6038647 0.1884058 1.154589
G       0.03448276        0.8458418     0.7444219    0.09939148 1.401623 0.2008114 0.6490872 0.1338742 1.146045
  tele19A192 foreign20A202
B  0.3864734   0.009661836
G  0.4016227   0.048681542

Coefficients of linear discriminants:
                             LD1
checkingstatus1A12  1.632240e-01
checkingstatus1A13  9.356218e-01
checkingstatus1A14  1.268479e+00
duration2          -2.235490e-02
history3A31        -4.385588e-01
history3A32         7.246792e-01
history3A33         8.600504e-01
history3A34         1.255190e+00
purpose4A41         1.171162e+00
purpose4A410        1.218227e+00
purpose4A42         5.931466e-01
purpose4A43         6.124543e-01
purpose4A44         2.618835e-02
purpose4A45         4.325512e-01
purpose4A46        -7.928380e-02
purpose4A48         1.530182e+00
purpose4A49         5.021521e-01
amount5            -7.038674e-05
savings6A62         1.617321e-01
savings6A63         3.983325e-01
savings6A64         8.459010e-01
savings6A65         4.830776e-01
employ7A72          2.665536e-01
employ7A73          3.993222e-01
employ7A74          8.689748e-01
employ7A75          4.717116e-01
installment8       -2.444648e-01
status9A92          4.967676e-01
status9A93          9.906082e-01
status9A94          4.457032e-01
others10A102       -6.671195e-01
others10A103        8.481579e-01
residence11         1.104461e-03
property12A122     -2.805593e-01
property12A123     -1.568844e-01
property12A124     -7.485387e-01
age13               7.876256e-03
otherplans14A142   -1.910317e-01
otherplans14A143    3.282307e-01
housing15A152       1.541348e-01
housing15A153       7.549236e-01
cards16            -2.194246e-01
job17A172           3.767577e-02
job17A173          -1.242648e-02
job17A174          -5.222328e-02
liable18           -2.937144e-01
tele19A192          1.913877e-01
foreign20A202       7.027756e-01

我需要的是一个可能显示我的数据点的图(当我看到它们时,图通常将LD1和LD2作为绘制数据点的轴,但我的例子只有LD1所以我的猜测是分散型图不可能)

0 个答案:

没有答案