Linear Discriminant Analysis (Lda)

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

Linear Discriminant Analysis

( LDA )
• Logistic regression is a classification
algorithm traditionally limited to only two-
class classification problems.
• If you have more than two classes then
Linear Discriminant Analysis is the preferred
linear classification technique.
Linear Discriminant Analysis
( LDA )
Two criteria are
used by LDA to
create a new axis:
1.Maximize the
distance
between means
of the two
classes.
2.Minimize the
variation within
each class.
library(MASS)
library(car)
data(wine, package = 'rattle.data’)
?wine # to know about data
df=wine
str(df)
summary(df)
dev.new()
scatterplotMatrix(df[2:6])
ggplot(df,aes(df$Alcohol,df$Malic,
col=df$Type))+
geom_point()

ggplot(df,aes(df$Ash,df$Alcalinity,
col=df$Type))+
geom_point()
set.seed(123)
rno=sample(nrow(df),nrow(df)*0.7)
trn=df[rno,]
tst=df[-rno,]
# LDA model building

library(caret)
lda1=train(Type~.,data=trn,method="lda")
Lda1
# LDA – Prediction & Accuracy

lda1.pred=predict(lda1,newdata = tst)

confusionMatrix(lda1.pred,tst$Type)
dev.new()
par(mfrow=c(2,7))
for(i in 2:14){
hist(df[,i],
main=paste('Distribution of',names(df[i]),sep='-'),
xlab = names(df[i]))
}
dev.new()
par(mfcol=c(2,7))
for(i in 2:14){
boxplot(df[,i]~df[,1],
main=paste('Boxplot-',names(df[i]),sep='-'),
xlab = names(df[1]),ylab=names(df[i]),
col=rainbow(3))
}

You might also like