Discriminative vs. Generative Learning CS 760@UW-Madison Goals for - - PowerPoint PPT Presentation

discriminative vs generative
SMART_READER_LITE
LIVE PREVIEW

Discriminative vs. Generative Learning CS 760@UW-Madison Goals for - - PowerPoint PPT Presentation

Discriminative vs. Generative Learning CS 760@UW-Madison Goals for the lecture you should understand the following concepts the relationship between logistic regression and Nave Bayes the relationship between discriminative and


slide-1
SLIDE 1

Discriminative vs. Generative Learning

CS 760@UW-Madison

slide-2
SLIDE 2

Goals for the lecture

you should understand the following concepts

  • the relationship between logistic regression and Naïve Bayes
  • the relationship between discriminative and generative learning
  • when discriminative/generative is likely to learn more accurate

models

slide-3
SLIDE 3

Review

slide-4
SLIDE 4

Discriminative vs. Generative

Discriminative approach:

  • hypothesis ℎ ∈ 𝐼 directly predicts the label given the features

𝑧 = ℎ(𝑦) or more generally, 𝑞 𝑧 𝑦 = ℎ(𝑦)

  • then define a loss function 𝑀(ℎ) and find hypothesis with min. loss

Generative approach:

  • hypothesis ℎ ∈ 𝐼 specifies a generative story for how the data was

created: 𝑞(𝑦, 𝑧) = ℎ(𝑦, 𝑧)

  • then pick a hypothesis by maximum likelihood estimation (MLE) or

Maximum A Posteriori (MAP)

slide-5
SLIDE 5

Summary: generative approach

  • Step 1: specify the joint data distribution (generative story)
  • Step 2: use MLE or MAP for training
  • Step 3: use Bayes’ rule for inference on test instances
  • Example: Naïve Bayes (conditional independence)

𝑞 𝑦, 𝑧 = 𝑞 𝑧 𝑞 𝑦 𝑧 = 𝑞 𝑧 ෑ

𝑗

𝑞(𝑦𝑗|𝑧)

slide-6
SLIDE 6

Summary: discriminative approach

  • Step 1: specify the hypothesis class
  • Step 2: specify the loss
  • Step 3: design optimization algorithm for training

How to design the hypotheses and the loss? Can design by a generative approach!

  • Step 0: specify 𝑞 𝑦 𝑧 and 𝑞(𝑧)
  • Step 1: compute hypotheses 𝑞(𝑧|𝑦) using Bayes’ rule
  • Step 2: use conditional MLE to derive the negative log-

likelihood loss (or use MAP to derive the loss)

  • Step 3: design optimization algorithm for training
  • Example: logistic regression
slide-7
SLIDE 7

Logistic regression

  • Suppose the class-conditional densities 𝑞 𝑦 𝑧 is normal

𝑞 𝑦 𝑧 = 𝑞 𝑦 𝑍 = 𝑧 = 𝑂 𝑦|𝜈𝑧, 𝐽 = 1 2𝜌 𝑒/2 exp − 1 2 𝑦 − 𝜈𝑧

2

  • Then conditional probability by Bayes’ rule:

𝑞 𝑍 = 𝑧|𝑦 = 𝑞 𝑦|𝑍 = 𝑧 𝑞(𝑍 = 𝑧) σ𝑙 𝑞 𝑦|𝑍 = 𝑙 𝑞(𝑍 = 𝑙) = exp(𝑏𝑧) σ𝑙 exp(𝑏𝑙) where 𝑏𝑙 ≔ ln 𝑞 𝑦 𝑍 = 𝑙 𝑞 𝑍 = 𝑙 = − 1 2 𝑦𝑈𝑦 + 𝑥𝑙

𝑈

𝑦 + 𝑐𝑙 with 𝑥𝑙 = 𝜈𝑙, 𝑐𝑙 = − 1 2 𝜈𝑙

𝑈𝜈𝑙 + ln 𝑞 𝑍 = 𝑙 + ln

1 2𝜌 𝑒/2

slide-8
SLIDE 8

Logistic regression

  • Suppose the class-conditional densities 𝑞 𝑦 𝑧 is normal

𝑞 𝑦 𝑧 = 𝑞 𝑦 𝑍 = 𝑧 = 𝑂 𝑦|𝜈𝑧, 𝐽 = 1 2𝜌 𝑒/2 exp − 1 2 𝑦 − 𝜈𝑧

2

  • Cancel out −

1 2 𝑦𝑈𝑦, we have

𝑞 𝑍 = 𝑧|𝑦 = exp(𝑏𝑧) σ𝑙 exp(𝑏𝑙) , 𝑏𝑙 ≔ 𝑥𝑙 𝑈𝑦 + 𝑐𝑙 where 𝑥𝑙 = 𝜈𝑙, 𝑐𝑙 = − 1 2 𝜈𝑙

𝑈𝜈𝑙 + ln 𝑞 𝑍 = 𝑙 + ln

1 2𝜌 𝑒/2

slide-9
SLIDE 9

Logistic regression: summary

  • Suppose the class-conditional densities 𝑞 𝑦 𝑧 is normal

𝑞 𝑦 𝑧 = 𝑞 𝑦 𝑍 = 𝑧 = 𝑂 𝑦|𝜈𝑧, 𝐽 = 1 2𝜌 𝑒/2 exp − 1 2 𝑦 − 𝜈𝑧

2

  • Then

𝑞 𝑍 = 𝑧|𝑦 = exp( 𝑥𝑧 𝑈𝑦 + 𝑐𝑧) σ𝑙 exp( 𝑥𝑙 𝑈𝑦 + 𝑐𝑙) which is the hypothesis class for multiclass logistic regression

  • Training: find parameters {𝑥𝑙, 𝑐𝑙} that minimize the negative

log-likelihood loss − 1 𝑛 ෍

𝑘=1 𝑛

log 𝑞 𝑧 = 𝑧(𝑘) 𝑦(𝑘)

slide-10
SLIDE 10

Naïve Bayes vs. Logistic Regression

slide-11
SLIDE 11

Connecting Naïve Bayes and logistic regression

  • Interesting observation: logistic regression is derived from the

generative story 𝑞 𝑦 𝑧 = 𝑞 𝑦 𝑍 = 𝑧 = 𝑂 𝑦|𝜈𝑧, 𝐽 = 1 2𝜌 𝑒/2 exp − 1 2 𝑦 − 𝜈𝑧

2

= 1 2𝜌 𝑒/2 ෑ

𝑗

exp − 1 2 𝑦𝑗 − 𝑣𝑧𝑗

2

which is a special case of Naïve Bayes!

  • Is the general Naïve Bayes assumption enough to get logistic

regression? (Instead of the more special Normal distribution assumption)

  • Yes, with an additional linearity assumption
slide-12
SLIDE 12

Naïve Bayes revisited

consider Naïve Bayes for a binary classification task expanding denominator dividing everything by numerator

) ,..., ( ) 1 | ( ) 1 ( ) ,..., | 1 (

1 1 1 n n i i n

x x P Y x P Y P x x Y P

=

= = = =

  

= = =

= = + = = = = =

n i i n i i n i i

Y x P Y P Y x P Y P Y x P Y P

1 1 1

) | ( ) ( ) 1 | ( ) 1 ( ) 1 | ( ) 1 (

 

= =

= = = = + =

n i i n i i

Y x P Y P Y x P Y P

1 1

) 1 | ( ) 1 ( ) | ( ) ( 1 1

slide-13
SLIDE 13

Naïve Bayes revisited

applying exp(ln(a)) = a applying ln(a/b) = -ln(b/a)

 

= =

= = = = + = =

n i i n i i n

Y x P Y P Y x P Y P x x Y P

1 1 1

) 1 | ( ) 1 ( ) | ( ) ( 1 1 ) ,..., | 1 (                         = = = = + =

 

= = n i i n i i

Y x P Y P Y x P Y P

1 1

) 1 | ( ) 1 ( ) | ( ) ( ln exp 1 1                         = = = = − + =

 

= = n i i n i i

Y x P Y P Y x P Y P

1 1

) | ( ) ( ) 1 | ( ) 1 ( ln exp 1 1

slide-14
SLIDE 14

Naïve Bayes revisited

converting log of products to sum of logs

Does this look familiar?

                        = = = = − + = =

 

= = n i i n i i n

Y x P Y P Y x P Y P x x Y P

1 1 1

) | ( ) ( ) 1 | ( ) 1 ( ln exp 1 1 ) ,..., | 1 (                 = = −       = = − + = =

= n i i i n

Y x P Y x P Y P Y P x x Y P

1 1

) | ( ) 1 | ( ln ) ( ) 1 ( ln exp 1 1 ) ,..., | 1 (

slide-15
SLIDE 15

              + − + =

= n i i ix

w w x f

1

exp 1 1 ) (                 = = −       = = − + = =

= n i i i n

Y x P Y x P Y P Y P x x Y P

1 1

) | ( ) 1 | ( ln ) ( ) 1 ( ln exp 1 1 ) ,..., | 1 (

Naïve Bayes vs. logistic regression

Naïve Bayes logistic regression Linearity assumption: the log-ratio is linear in 𝑦

slide-16
SLIDE 16

              + − + =

= n i i ix

w w x f

1

exp 1 1 ) (                 = = −       = = − + = =

= n i i i n

Y x P Y x P Y P Y P x x Y P

1 1

) | ( ) 1 | ( ln ) ( ) 1 ( ln exp 1 1 ) ,..., | 1 (

Naïve Bayes vs. logistic regression

Naïve Bayes logistic regression Summary: If we begin with a Naïve Bayes generative story to derive a discriminative approach (assuming linearity), we get logistic regression! Linearity assumption: the log-ratio is linear in 𝑦

slide-17
SLIDE 17

              + − + =

= n i i ix

w w x f

1

exp 1 1 ) (                 = = −       = = − + = =

= n i i i n

Y x P Y x P Y P Y P x x Y P

1 1

) | ( ) 1 | ( ln ) ( ) 1 ( ln exp 1 1 ) ,..., | 1 (

Naïve Bayes vs. logistic regression

Naïve Bayes logistic regression Summary: If we begin with a Naïve Bayes generative story to derive a discriminative approach (assuming linearity), we get logistic regression! Generative counterpart of logistic regression Discriminative counterpart of Naïve Bayes

slide-18
SLIDE 18

Naïve Bayes vs. logistic regression

Conditional Independence (Naïve Bayes assumption) Naïve Bayes method Logistic regression Discriminative approach (+ linearity assumption) Generative approach

slide-19
SLIDE 19

Logistic regression as a neural net

Y Color=red Color=blue Size=big Size=small 1

ln P(Y =1) P(Y = 0) æ è ç ö ø ÷ ln P(red |Y =1) P(red |Y = 0) æ è ç ö ø ÷ ln P(blue |Y =1) P(blue |Y = 0) æ è ç ö ø ÷

The connection can give interpretation for the weights in logistic regression: weights correspond to log ratios

slide-20
SLIDE 20

Which is better?

slide-21
SLIDE 21

Naïve Bayes vs. logistic regression

  • they have the same functional form, and thus have the same

hypothesis space bias (recall our discussion of inductive bias)

  • Do they learn the same models?

In general, no. They use different methods to estimate the model parameters. Naïve Bayes uses MLE to learn the parameters 𝑞(𝑦𝑗|𝑧), whereas LR minimizes the loss to learn the parameters 𝑥𝑗.

slide-22
SLIDE 22

asymptotic comparison (# training instances → ∞)

  • when conditional independence assumptions made by NB are

correct, NB and LR produce identical classifiers when conditional independence assumptions are incorrect

  • logistic regression is less biased; learned weights may be able to

compensate for incorrect assumptions (e.g. what if we have two redundant but relevant features)

  • therefore LR expected to outperform NB when given lots of training

data

Naïve Bayes vs. logistic regression

slide-23
SLIDE 23

Naïve Bayes vs. logistic regression

non-asymptotic analysis [Ng & Jordan, NIPS 2001]

  • consider convergence of parameter estimates; how many training

instances are needed to get good estimates naïve Bayes: O(log n) logistic regression: O(n)

  • naïve Bayes converges more quickly to its (perhaps less accurate)

asymptotic estimates

  • therefore NB expected to outperform LR with small training sets

n = # features

slide-24
SLIDE 24

Experimental comparison of NB and LR

naïve Bayes logistic regression size of training set Ng and Jordan compared learning curves for the two approaches on 15 data sets (some w/discrete features, some w/continuous features)

slide-25
SLIDE 25

Experimental comparison of NB and LR

naïve Bayes logistic regression general trend supports theory

  • NB has lower predictive error when training sets are small
  • the error of LR approaches or is lower than NB when training sets are

large

slide-26
SLIDE 26

Discussion

  • NB/LR is one case of a pair of generative/discriminative approaches

for the same model class

  • if modeling assumptions are valid (e.g. conditional independence of

features in NB) the two will produce identical classifiers in the limit (# training instances → ∞)

  • if modeling assumptions are not valid, the discriminative approach is

likely to be more accurate for large training sets

  • for small training sets, the generative approach is likely to be more

accurate because parameters converge to their asymptotic values more quickly (in terms of training set size)

  • Q: How can we tell whether our training set size is more appropriate

for a generative or discriminative method? A: Empirically compare the two.

slide-27
SLIDE 27

THANK YOU

Some of the slides in these lectures have been adapted/borrowed from materials developed by Mark Craven, David Page, Jude Shavlik, Tom Mitchell, Nina Balcan, Elad Hazan, Tom Dietterich, and Pedro Domingos.