Linear Discriminant Analysis (LDA)

Published by onesixx on

StatQuest:https://statquest.org/2016/07/10/statquest-linear-discriminant-analysis-lda-clearly-explained/
https://www.youtube.com/watch?v=azXCzI57Yfc

 

library(MASS) 
library(tidyverse)
 
## Load Dataset
data("iris")
(my.data <- as_tibble(iris))
str(my.data)

## create LDA model
model <- lda(formula=Species~., data=my.data)
 
## get the x,y coordinates for the LDA plot
data.lda.values <- predict(model)
 
## draw a Graph
plot.data <- data.frame(X=data.lda.values$x[,1], Y=data.lda.values$x[,2], Species=my.data$Species)

p <- ggplot(data=plot.data, aes(x=X, y=Y)) +
    geom_point(aes(color=Species)) +
    theme_bw()
p

#ggsave(file="my_graph.pdf") ## to save the graph 

 

 

 

Categories: book:ISLR

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x