Linear discrimination




Дата канвертавання22.04.2016
Памер12.7 Kb.
Linear discrimination

a <- lda(Species~.,iris)


Prior probabilities of groups:

setosa versicolor virginica

0.3333333 0.3333333 0.3333333


Group means:

Sepal.Length Sepal.Width Petal.Length Petal.Width

setosa 5.006 3.428 1.462 0.246

versicolor 5.936 2.770 4.260 1.326

virginica 6.588 2.974 5.552 2.026
Coefficients of linear discriminants:

LD1 LD2


Sepal.Length 0.8293776 0.02410215

Sepal.Width 1.5344731 2.16452123

Petal.Length -2.2012117 -0.93192121

Petal.Width -2.8104603 2.83918785


Proportion of trace:

LD1 LD2


0.9912 0.0088

ld<-predict(a,dimen=2)$x

plot(ld,type="n")

text(ld,labels=c("S","C","V")[iris$Species],cex=0.8)




plot(a,dimen=1)




plot(a,type="density",dimen=1)





Classification

train<-sample(1:150,50)

a<-lda(Species~.,iris[train,])

y<-predict(a,iris[-train,])$class

y
[1] setosa setosa setosa setosa setosa setosa

[7] setosa setosa setosa setosa setosa setosa

[13] setosa setosa setosa setosa setosa setosa

[19] setosa setosa setosa setosa setosa setosa

[25] setosa setosa setosa setosa versicolor versicolor

[31] versicolor versicolor versicolor versicolor versicolor versicolor

[37] versicolor versicolor versicolor versicolor versicolor versicolor

[43] versicolor versicolor versicolor versicolor versicolor versicolor

[49] versicolor versicolor virginica versicolor versicolor versicolor

[55] versicolor versicolor versicolor versicolor versicolor versicolor

[61] versicolor virginica virginica virginica virginica virginica

[67] virginica virginica virginica virginica virginica virginica

[73] virginica virginica virginica virginica virginica virginica

[79] virginica virginica virginica virginica virginica virginica

[85] virginica versicolor virginica virginica virginica virginica

[91] versicolor virginica virginica virginica virginica virginica

[97] virginica virginica virginica virginica

Levels: setosa versicolor virginica


sum(y==iris[-train,5])

[1] 97


База данных защищена авторским правом ©shkola.of.by 2016
звярнуцца да адміністрацыі

    Галоўная старонка