#5, First Floor, 4th Street , Dr. Subbarayan Nagar, Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to implement Linear Discriminant Analysis in R?
Description

To implement Linear Discriminant Analysis in R

Libraries required :

require(MASS)
require(ggplot2)
require(scales)
require(gridExtra)

Process

  Load the necessary libraries

  Load the data set

  Perform Linear Discriminant analysis on the data

  Take the summary

  Visualize the result

Sapmle Code

#Load necessary libraries
require(MASS)
require(ggplot2)
require(scales)
require(gridExtra)
data=read.csv(‘/……../iris.csv’)
#To Split 80% of data as training data
smp_size train_ind train test #Perform linear discriminant analysis
lda data=train)
#Take the summary
summary(lda)
lda$prior
lda$counts
lda$means
lda$scaling
lda$svd
lda$x
#Visualize the result
prop.lda = lda$svd^2/sum(lda$svd^2)
plda = predict(object = lda,newdata = data )
dataset = data.frame(species = data[,”species”],lda = plda$x)
p1 labs(x = paste(“LD1 (“, percent(prop.lda[1]), “)”, sep=””),
y = paste(“LD2 (“, percent(prop.lda[2]), “)”, sep=””))

grid.arrange(p1)

Screenshots