+ - 0:00:00
Notes for current slide
Notes for next slide

Logistic regression, LDA, QDA - Part 3

Dr. D’Agostino McGowan

1 / 19

Other forms of discriminant analysis

P(Y|X)=πkfk(x)l=1Kπlfl(x)

2 / 19

Other forms of discriminant analysis

P(Y|X)=πkfk(x)l=1Kπlfl(x)

  • When fk(x) are normal densities with the same covariance matrix Σ in each class, this is linear discriminant analysis
2 / 19

Other forms of discriminant analysis

P(Y|X)=πkfk(x)l=1Kπlfl(x)

  • When fk(x) are normal densities with the same covariance matrix Σ in each class, this is linear discriminant analysis
  • When fk(x) are normal densities with different covariance matrices Σk in each class, this is quadratic discriminant analysis
2 / 19

Other forms of discriminant analysis

P(Y|X)=πkfk(x)l=1Kπlfl(x)

  • When fk(x) are normal densities with the same covariance matrix Σ in each class, this is linear discriminant analysis
  • When fk(x) are normal densities with different covariance matrices Σk in each class, this is quadratic discriminant analysis
  • Lots of other forms are possible!
2 / 19

Quadratic Discriminant Analysis

δk(x)=12(xμk)TΣk1(xμk)+logπk

Why do you think this is called quadratic discriminant analysis?

3 / 19

Quadratic Discriminant Analysis

δk(x)=12(xμk)TΣk1(xμk)+logπk

Why do you think this is called quadratic discriminant analysis?

  • Because the Σk are different, the quadratic terms matter
3 / 19

Let's see it in R

library(MASS)
model <- qda(default ~ balance + student, data = Default)
predictions <- predict(model)
  • Use the qda() function in R from the MASS package
4 / 19

Let's see it in R

  • Let's use LDA to visualize the data
model <- lda(Species ~ ., data = iris)
predictions <- predict(model)
5 / 19

Let's see it in R

  • Let's use LDA to visualize the data
model <- lda(Species ~ ., data = iris)
predictions <- predict(model)
plot_data <- data.frame(outcome = iris$Species,
lda = predictions$x)
head(plot_data)
## outcome lda.LD1 lda.LD2
## 1 setosa 8.061800 0.3004206
## 2 setosa 7.128688 -0.7866604
## 3 setosa 7.489828 -0.2653845
## 4 setosa 6.813201 -0.6706311
## 5 setosa 8.132309 0.5144625
## 6 setosa 7.701947 1.4617210
6 / 19

Let's see it in R

  • Let's use LDA to visualize the data
ggplot(data = plot_data,
mapping = aes(x = lda.LD1, y = lda.LD2, color = outcome)) +
geom_point()

7 / 19

ggplot2 tidyverse

  • ggplot2 is tidyverse's data visualization package
  • The gg in "ggplot2" stands for Grammar of Graphics
  • It is inspired by the book Grammar of Graphics by Leland Wilkinson
  • A grammar of graphics is a tool that enables us to concisely describe the components of a graphic

Source: BloggoType

8 / 19

ggplot2

What function creates the plot?

ggplot(data = plot_data,
mapping = aes(x = lda.LD1, y = lda.LD2, color = outcome)) +
geom_point() +
labs(x = "LD1", y = "LD2")

9 / 19

ggplot2

What data set is being plotted?

ggplot(data = plot_data,
mapping = aes(x = lda.LD1, y = lda.LD2, color = outcome)) +
geom_point() +
labs(x = "LD1", y = "LD2")

10 / 19

ggplot2

Which variables are on the x- and y-axis?

ggplot(data = plot_data,
mapping = aes(x = lda.LD1, y = lda.LD2, color = outcome)) +
geom_point() +
labs(x = "LD1", y = "LD2")

11 / 19

ggplot2

What variable in the dataset determines the color?

ggplot(data = plot_data,
mapping = aes(x = lda.LD1, y = lda.LD2, color = outcome)) +
geom_point() +
labs(x = "LD1", y = "LD2")

12 / 19

ggplot2

What does geom_point() mean?

ggplot(data = plot_data,
mapping = aes(x = lda.LD1, y = lda.LD2, color = outcome)) +
geom_point() +
labs(x = "LD1", y = "LD2")

13 / 19

Hello ggplot2!

  • ggplot() is the main function in ggplot2 and plots are constructed in layers
  • The structure of the code for plots can often be summarized as
ggplot +
geom_xxx
14 / 19

Hello ggplot2!

  • ggplot() is the main function in ggplot2 and plots are constructed in layers
  • The structure of the code for plots can often be summarized as
ggplot +
geom_xxx

or, more precisely

ggplot(data = [dataset], mapping = aes(x = [x-variable], y = [y-variable])) +
geom_xxx() +
other options
14 / 19

Hello ggplot2!

  • To use ggplot2 functions, first load tidyverse
15 / 19

Hello ggplot2!

  • To use ggplot2 functions, first load tidyverse
15 / 19

  • What is going on here?
16 / 19

  • What is going on here?
  • LDA is projecting the samples X onto a hyperplane with K1 dimensions.
16 / 19

  • What is going on here?
  • LDA is projecting the samples X onto a hyperplane with K1 dimensions.

    What is K here?

16 / 19

  • What is going on here?
  • LDA is projecting the samples X onto a hyperplane with K1 dimensions.
  • Why does this work?
  • LDA essentially classifies to the closest centroid, and they span a K - 1 dimensional plane.
17 / 19

  • What is going on here?
  • LDA is projecting the samples X onto a hyperplane with K1 dimensions.
  • Why does this work?
  • LDA essentially classifies to the closest centroid, and they span a K - 1 dimensional plane.
  • Even when K > 3, we can find the "best" 2-dimensional plane for vizualizing the discriminant rule by using the first two discriminant variables (LD1 and LD2)
17 / 19

Logistic Regression versus LDA

  • For the two-class problem ( K=2 ), LDA takes the form

log(p1(x)1p1(x))=log(p1p2)=c0+c1x1++cpxp

18 / 19

Logistic Regression versus LDA

  • For the two-class problem ( K=2 ), LDA takes the form

log(p1(x)1p1(x))=log(p1p2)=c0+c1x1++cpxp

  • This is the same form as logistic regression
18 / 19

Logistic Regression versus LDA

  • For the two-class problem ( K=2 ), LDA takes the form

log(p1(x)1p1(x))=log(p1p2)=c0+c1x1++cpxp

  • This is the same form as logistic regression
  • The difference is in how the parameters are estimated
18 / 19

Logistic Regression versus LDA

  • For the two-class problem ( K=2 ), LDA takes the form

log(p1(x)1p1(x))=log(p1p2)=c0+c1x1++cpxp

  • This is the same form as logistic regression
  • The difference is in how the parameters are estimated
    • Logistic regression uses the conditional likelihood based on P(Y|X) (discriminative learning)
18 / 19

Logistic Regression versus LDA

  • For the two-class problem ( K=2 ), LDA takes the form

log(p1(x)1p1(x))=log(p1p2)=c0+c1x1++cpxp

  • This is the same form as logistic regression
  • The difference is in how the parameters are estimated
    • Logistic regression uses the conditional likelihood based on P(Y|X) (discriminative learning)
    • LDA uses the full likelihood based on P(X,Y) (generative learning)
18 / 19

Logistic Regression versus LDA

  • For the two-class problem ( K=2 ), LDA takes the form

log(p1(x)1p1(x))=log(p1p2)=c0+c1x1++cpxp

  • This is the same form as logistic regression
  • The difference is in how the parameters are estimated
    • Logistic regression uses the conditional likelihood based on P(Y|X) (discriminative learning)
    • LDA uses the full likelihood based on P(X,Y) (generative learning)
    • The results are often similar
18 / 19

Summary

  • Logistic regression is very popular for classification, especially when K=2
  • LDA is useful when n is small, or the classes are well separated, and normality assumptions are reasonable. Also when K>2
19 / 19

Summary

  • Logistic regression is very popular for classification, especially when K=2
  • LDA is useful when n is small, or the classes are well separated, and normality assumptions are reasonable. Also when K>2
  • QDA is similar to LDA, but it is more flexible because it allows the covariance of the predictors to be different for each class, k
19 / 19

Summary

  • Logistic regression is very popular for classification, especially when K=2
  • LDA is useful when n is small, or the classes are well separated, and normality assumptions are reasonable. Also when K>2
  • QDA is similar to LDA, but it is more flexible because it allows the covariance of the predictors to be different for each class, k
  • See Section 4.5 in your book for some comparisons of logistic regression, LDA, and KNN.
19 / 19

Other forms of discriminant analysis

P(Y|X)=πkfk(x)l=1Kπlfl(x)

2 / 19
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow