uva cs 4501: machine learning lecture 17: generative bayes ... · machine learning lecture 17:...

89
UVA CS 4501: Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer Science

Upload: others

Post on 02-Aug-2020

6 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

UVACS4501:MachineLearning

Lecture17:GenerativeBayes

Classifiers

Dr.YanjunQi

UniversityofVirginia

DepartmentofComputerScience

Page 2: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Wherearewe?èMajorsectionsofthiscourse

q Regression(supervised)q Classification(supervised)q Unsupervisedmodelsq Learningtheory

12/6/18

Dr.YanjunQi/UVACS

2

Page 3: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Wherearewe?èThreemajorsectionsforclassification

•  We can divide the large variety of classification approaches into roughly three major types

1. Discriminative - directly estimate a decision rule/boundary - e.g., SVM , NN , decision tree 2. Generative: - build a generative statistical model - e.g., naïve bayes classifier, Bayesian networks 3. Instance based classifiers - Use observation directly (no models) - e.g. K nearest neighbors

12/6/18

Dr.YanjunQi/UVACS

3

Page 4: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

TodayRecap:GenerativeBayesClassifiers

ü BayesClassifier§  GenerativeBayesClassifier

ü NaïveBayesClassifierü GaussianBayesClassifiers

§  Gaussiandistribution§  NaïveGaussianBC§  Not-naïveGaussianBCèLDA,QDA

12/6/18

Dr.YanjunQi/UVACS

4

Page 5: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

•  Treat each feature attribute and the class label as random variables.

•  Given a sample x with attributes ( x1, x2, … , xp ): – Goal is to predict its class c. – Specifically, we want to find the class that maximizes

p( c | x1, x2, … , xp ).

•  Can we estimate p(Ci |x) = p( Ci | x1, x2, … , xp ) directly from data?

Review: Bayes classifiers

12/6/18

Dr.YanjunQi/UVACS/s18

5

cMAP = argmaxcj∈C

P(cj | x1, x2,…, xp ) MAPRule

Page 6: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Bayes classifiers è MAP classification rule

•  Establishing a probabilistic model

for classification –  (1) Discriminative –  (2) Generative

12/6/18

Dr.YanjunQi/UVACS

6

Page 7: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Review: Establishing a probabilistic model for classification

–  (1) Discriminative model

x = (x1 ,x2 ,⋅⋅⋅,xp)

Discriminative

Probabilistic Classifier

1x 2x xp

)|( 1 xcP )|( 2 xcP )|( xLcP

•••

•••

12/6/18AdaptfromProf.KeChenNBslides

7

Dr.YanjunQi/UVACS/s18

argmax

c∈CP(c |X),C = {c1 ,⋅⋅⋅,cL}

Page 8: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

(2) Generative

P(X |C),C = c1 ,⋅⋅⋅,cL ,X = (X1 ,⋅⋅⋅,Xp)

Generative Probabilistic Model

for Class 1

)|( 1cP x

1x 2x xp•••

Generative Probabilistic Model

for Class 2

)|( 2cP x

1x 2x xp•••

Generative Probabilistic Model

for Class L

)|( LcP x

1x 2x xp•••

•••

x = (x1, x2, ⋅ ⋅ ⋅, xp )12/6/18

Dr.YanjunQi/UVACS

AdaptfromProf.KeChenNBslides8

Page 9: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Generative BC

P(X |C),C = c1 ,⋅⋅⋅,cL ,X = (X1 ,⋅⋅⋅,Xp)

Generative Probabilistic Model

for Class 1

)|( 1cP x

1x 2x xp•••

Generative Probabilistic Model

for Class 2

)|( 2cP x

1x 2x xp•••

Generative Probabilistic Model

for Class L

)|( LcP x

1x 2x xp•••

•••

x = (x1, x2, ⋅ ⋅ ⋅, xp )12/6/18

Dr.YanjunQi/UVACS

AdaptfromProf.KeChenNBslides9

Page 10: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Generative BC

P(X |C),C = c1 ,⋅⋅⋅,cL ,X = (X1 ,⋅⋅⋅,Xp)

Generative Probabilistic Model

for Class 1

)|( 1cP x

1x 2x xp•••

Generative Probabilistic Model

for Class 2

)|( 2cP x

1x 2x xp•••

Generative Probabilistic Model

for Class L

)|( LcP x

1x 2x xp•••

•••

x = (x1, x2, ⋅ ⋅ ⋅, xp )12/6/18

Dr.YanjunQi/UVACS

AdaptfromProf.KeChenNBslides10

Page 11: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

ReviewProbability:Ifhardtodirectlyestimatefromdata,mostlikelywecan

estimate

•  1.Jointprobability– UseChainRule

•  2.Marginalprobability– Usethetotallawofprobability

•  3.Conditionalprobability– UsetheBayesRule

12/6/18

Dr.YanjunQi/UVACS6316/f16

11

Page 12: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Review : Bayes’ Rule – for Generative Bayes Classifiers

P(C | X) = P(X |C)P(C)P(X)

12

P(C1), P(C2), …, P(CL) P(C1|x), P(C2|x), …, P(CL|x)

12/6/18

Dr.YanjunQi/UVACS

P(Ci |X) =

P(X |Ci )P(Ci )P(X)

Page 13: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Review : Bayes’ Rule – for Generative Bayes Classifiers

P(C | X) = P(X |C)P(C)P(X)

13

P(C1), P(C2), …, P(CL)

Prior

P(C1|x), P(C2|x), …, P(CL|x)

Posterior

12/6/18

Dr.YanjunQi/UVACS

P(C |X) = P(X | C)P(C)P(X)

Page 14: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Establishing a probabilistic model for classification through generative modeling

Generative Probabilistic Model

for Class 1

)|( 1cP x

1x 2x xp•••

Generative Probabilistic Model

for Class 2

)|( 2cP x

1x 2x xp•••

Generative Probabilistic Model

for Class L

)|( LcP x

1x 2x xp•••

•••

x = (x1, x2, ⋅ ⋅ ⋅, xp )12/6/18 AdaptfromProf.KeChenNBslides

argmax

Ci

P(Ci |X )= argmaxCi

P(X ,Ci )= argmaxCi

P(X |Ci )P(Ci )

14

Dr.YanjunQi/UVACS/s18

Page 15: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Summary:

–  Apply Bayes rule to get posterior probabilities

–  Then apply the MAP rule

LicCPcC|P

PcCPcC|P|cCP

ii

iii

,,2,1 for )()(

)()()( )(

⋅⋅⋅====∝

=======

xXxX

xXxX

12/6/18

Dr.YanjunQi/UVACS

AdaptfromProf.KeChenNBslides15

Page 16: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

ADatasetforclassification

•  Data/points/instances/examples/samples/records:[rows]•  Features/attributes/dimensions/independentvariables/covariates/predictors/regressors:[columns,exceptthelast]•  Target/outcome/response/label/dependentvariable:specialcolumntobepredicted[lastcolumn]

12/6/18 16

Output as Discrete Class Label

C1, C2, …, CL

C

C

Generative

Dr.YanjunQi/UVACS/s18

argmax

c∈CP(c |X )= argmax

c∈CP(X ,c)= argmax

c∈CP(X |c)P(c)

argmax

c∈CP(c |X)C = {c1 ,⋅⋅⋅,cL}Discriminative

thislecture!

Page 17: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

An Example

•  Example: Play Tennis

C

12/6/18

Dr.YanjunQi/UVACS

17

Page 18: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

An Example

•  Example: Play Tennis

C

12/6/18

Dr.YanjunQi/UVACS

18

Page 19: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Example

•  Example: Play Tennis

C

12/6/18

Dr.YanjunQi/UVACS

19

Page 20: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

12/6/18

Dr.YanjunQi/UVACS

20

•  maximum likelihood estimates – simply use the frequencies in the data

CheckL12-MLELecturefor

Why

Directlyestimatefrom

data

Page 21: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

12/6/18 21

•  Learning Phase

C

Outlook (3 values)

Temperature(3 values)

Humidity(2 values)

Wind(2 values)

Play=Yes Play=No

sunny hot high weak 0/9 1/5sunny hot high strong …/9 …/5sunny hot normal weak …/9 …/5sunny hot normal strong …/9 …/5

…. …. …. …. …. ….…. …. …. …. …. ….…. …. …. …. …. ….…. …. …. …. …. ….

3*3*2*2 [conjunctions of attributes] * 2 [two classes]=72 parameters

P(Play=Yes) = 9/14 P(Play=No) = 5/14P(C1), P(C2), …, P(CL)

P(X1,X2 ,…, Xp|C1), P(X1,X2 ,…, Xp|C2)

Dr.YanjunQi/UVACS

Generative Bayes Classifier:

Page 22: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Generative Bayes Classifier:

•  Test Phase

–  Given an unknown instance

–  Look up tables to assign the label c* to Xts if

–  Given a new instance, x’=(Outlook=Sunny, Temperature=Cool, Humidity=High, Wind=Strong)

Dr.YanjunQi/UVACS

12/6/18 22

′Xts = ( ′a1 ,⋅⋅⋅, ′ap)

P̂( ′a1 ,⋅⋅⋅ ′ap |c* )P̂(c* )> P̂( ′a1 ,⋅⋅⋅ ′ap |c)P̂(c),c ≠ c* , c = c1 ,⋅⋅⋅,cL

LastPage

Page 23: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

12/6/18

Dr.YanjunQi/UVACS

23

Page 24: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

TodayRecap:GenerativeBayesClassifiers

ü BayesClassifier§  GenerativeBayesClassifier

ü NaïveBayesClassifierü GaussianBayesClassifiers

§  Gaussiandistribution§  NaïveGaussianBC§  Not-naïveGaussianBCèLDA,QDA

12/6/18

Dr.YanjunQi/UVACS

24

Page 25: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Naïve Bayes Classifier

•  Bayes classification

Difficulty: learning the joint probability

•  Naïve Bayes classification –  Assumption that all input attributes are conditionally independent!

12/6/18

Dr.YanjunQi/UVACS

25

argmax

c j∈CP(x1 ,x2 ,…,xp |c j )P(c j )

Page 26: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Naïve Bayes Classifier

•  Bayes classification

Difficulty: learning the joint probability

•  Naïve Bayes classification –  Assumption that all input attributes are conditionally independent!

12/6/18

Dr.YanjunQi/UVACS

26

argmax

c j∈CP(x1 ,x2 ,…,xp |c j )P(c j )

Page 27: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Naïve Bayes Classifier

•  Naïve Bayes classification –  Assumption that all input attributes are conditionally independent!

P(X1 ,X2 ,⋅⋅⋅,Xp |C)= P(X1 |X2 ,⋅⋅⋅,Xp ,C)P(X2 ,⋅⋅⋅,Xp |C) = P(X1 |C)P(X2 ,⋅⋅⋅,Xp |C) = P(X1 |C)P(X2 |C)⋅⋅⋅P(Xp |C)

12/6/18

Dr.YanjunQi/UVACS

27

Page 28: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Naïve Bayes Classifier

•  Naïve Bayes classification –  Assumption that all input attributes are conditionally independent!

–  MAP classification rule: for a sample

[P(x1 | c*) ⋅ ⋅ ⋅P(xp | c*)]P(c*)> [P(x1 | c) ⋅ ⋅ ⋅P(xp | c)]P(c),

c ≠ c*, c = c1, ⋅ ⋅ ⋅,cL

x = (x1 ,x2 ,⋅⋅⋅,xp)

12/6/18

Dr.YanjunQi/UVACS

28

P(X1 ,X2 ,⋅⋅⋅,Xp |C)= P(X1 |C)P(X2 |C)⋅⋅⋅P(Xp |C)

Page 29: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Naïve Bayes Classifier

•  Naïve Bayes classification –  Assumption that all input attributes are conditionally independent!

–  MAP classification rule: for a sample

[P(x1 | c*) ⋅ ⋅ ⋅P(xp | c*)]P(c*)> [P(x1 | c) ⋅ ⋅ ⋅P(xp | c)]P(c),

c ≠ c*, c = c1, ⋅ ⋅ ⋅,cL

x = (x1 ,x2 ,⋅⋅⋅,xp)

12/6/18

Dr.YanjunQi/UVACS

29

P(X1 ,X2 ,⋅⋅⋅,Xp |C)= P(X1 |C)P(X2 |C)⋅⋅⋅P(Xp |C)

Page 30: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Naïve Bayes Classifier

•  Naïve Bayes classification –  Assumption that all input attributes are conditionally independent!

–  MAP classification rule: for a sample

[P(x1 | c*) ⋅ ⋅ ⋅P(xp | c*)]P(c*)> [P(x1 | c) ⋅ ⋅ ⋅P(xp | c)]P(c),

c ≠ c*, c = c1, ⋅ ⋅ ⋅,cL

x = (x1 ,x2 ,⋅⋅⋅,xp)

12/6/18

Dr.YanjunQi/UVACS

30

P(X1 ,X2 ,⋅⋅⋅,Xp |C)= P(X1 |C)P(X2 |C)⋅⋅⋅P(Xp |C)

Page 31: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Naïve Bayes Classifier (for discrete input attributes) - training

•  Naïve Bayes Algorithm (for discrete input attributes)

–  Learning Phase: Given a training set S,

Output: conditional probability tables; for elements

For each target value of ci (ci = c1,⋅ ⋅ ⋅,cL )

P̂(C = ci )← estimate P(C = ci ) with examples in S; For every attribute value x jk of each attribute X j ( j =1, ⋅ ⋅ ⋅, p; k =1, ⋅ ⋅ ⋅,K j )

P̂(X j = x jk | C = ci )← estimate P(X j = x jk | C = ci ) with examples in S;

Xj, K j × L

12/6/18

Dr.YanjunQi/UVACS

31

Page 32: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Naïve Bayes Classifier (for discrete input attributes) - training

•  Naïve Bayes Algorithm (for discrete input attributes)

–  Learning Phase: Given a training set S,

Output: conditional probability tables; for elements

For each target value of ci (ci = c1,⋅ ⋅ ⋅,cL )

P̂(C = ci )← estimate P(C = ci ) with examples in S; For every attribute value x jk of each attribute X j ( j =1, ⋅ ⋅ ⋅, p; k =1, ⋅ ⋅ ⋅,K j )

P̂(X j = x jk | C = ci )← estimate P(X j = x jk | C = ci ) with examples in S;

Xj, K j × L

12/6/18

Dr.YanjunQi/UVACS

32

Page 33: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Naïve Bayes Classifier (for discrete input attributes) - training

•  Naïve Bayes Algorithm (for discrete input attributes)

–  Learning Phase: Given a training set S,

Output: conditional probability tables; for elements

Foreachtargetvalueofci (ci = c1 ,⋅⋅⋅,cL )P̂(C = ci )←estimateP(C = ci )withexamplesinS;Foreveryattributevaluex jk ofeachattributeX j( j =1,⋅⋅⋅,p;k =1,⋅⋅⋅,K j )P̂(X j = x jk |C = ci )←estimateP(X j = x jk |C = ci )withexamplesinS;

Xj, K j × L

12/6/18

Dr.YanjunQi/UVACS

33

Page 34: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Naïve Bayes (for discrete input attributes) - testing

•  Naïve Bayes Algorithm (for discrete input attributes)

–  Test Phase: Given an unknown instance

Look up tables to assign the label c* to X’ if [P̂( !a1 | c*) ⋅ ⋅ ⋅ P̂( !ap | c*)]P̂(c*)> [P̂( !a1 | c) ⋅ ⋅ ⋅ P̂( !ap | c)]P̂(c),

c ≠ c*, c = c1, ⋅ ⋅ ⋅,cL

!X = ( !a1, ⋅ ⋅ ⋅, !ap )

12/6/18

Dr.YanjunQi/UVACS

34

Page 35: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

An Example

•  Example: Play Tennis

C

12/6/18 35

Page 36: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

An Example

•  Example: Play Tennis

C

12/6/18

Dr.YanjunQi/UVACS

36

Page 37: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Learning (training) the NBC Model

C

X1 X2 X5 X3 X4 X6

37 12/6/18

Dr.YanjunQi/UVACS

Page 38: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Learning (training) the NBC Model

•  maximum likelihood estimates: –  simply use the frequencies in the data

)(),(

)|(ˆj

jiiji cCN

cCxXNcxP

===

=

C

X1 X2 X5 X3 X4 X6

NcCN

cP jj

)()(ˆ

==

38 12/6/18

Dr.YanjunQi/UVACS

Page 39: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Learning (training) the NBC Model

•  maximum likelihood estimates –  simply use the frequencies in the data

)(),(

)|(ˆj

jiiji cCN

cCxXNcxP

===

=

C

X1 X2 X5 X3 X4 X6

NcCN

cP jj

)()(ˆ

==

39 12/6/18

Dr.YanjunQi/UVACS

Page 40: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

12/6/18

Dr.YanjunQi/UVACS

40

OutlookPlay=YesPlay=No

Sunny

Overcast

Rain

Temperature Play=Yes Play=NoHot

Mild

Cool

Humidity Play=YesPlay=No

High

Normal

Wind Play=YesPlay=No

Strong

Weak

P(Play=Yes) = ?? P(Play=No) = ?? P(C1), P(C2), …, P(CL)

P(X2|C1), P(X2|C2)

P(X4|C1), P(X4|C2)

EstimateP(X j = x jk |C = ci )withexamplesintraining;

Page 41: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

12/6/18

Dr.YanjunQi/UVACS

41

Page 42: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

•  Learning Phase

OutlookPlay=YesPlay=NoSunny 2/9 3/5

Overcast 4/9 0/5Rain 3/9 2/5

Temperature Play=Yes Play=NoHot 2/9 2/5Mild 4/9 2/5Cool 3/9 1/5

Humidity Play=YesPlay=No

High 3/9 4/5Normal 6/9 1/5

Wind Play=YesPlay=No

Strong 3/9 3/5Weak 6/9 2/5

P(Play=Yes) = 9/14 P(Play=No) = 5/14 P(C1), P(C2), …, P(CL)

P(X2|C1), P(X2|C2)

P(X4|C1), P(X4|C2)

12/6/18

3+3+2+2 [naïve assumption] * 2 [two classes]= 20 parameters

42

Dr.YanjunQi/UVACS

EstimateP(X j = x jk |C = ci )withexamplesintraining;

Page 43: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

•  Learning Phase

OutlookPlay=YesPlay=NoSunny 2/9 3/5

Overcast 4/9 0/5Rain 3/9 2/5

Temperature Play=Yes Play=NoHot 2/9 2/5Mild 4/9 2/5Cool 3/9 1/5

Humidity Play=YesPlay=No

High 3/9 4/5Normal 6/9 1/5

Wind Play=YesPlay=No

Strong 3/9 3/5Weak 6/9 2/5

P(Play=Yes) = 9/14 P(Play=No) = 5/14 P(C1), P(C2), …, P(CL)

P(X2|C1), P(X2|C2)

P(X4|C1), P(X4|C2)

12/6/18

3+3+2+2 [naïve assumption] * 2 [two classes]= 20 parameters

43

Dr.YanjunQi/UVACS

EstimateP(X j = x jk |C = ci )withexamplesintraining;

Page 44: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Testing the NBC Model

•  Test Phase

–  Given a new instance, x’=(Outlook=Sunny, Temperature=Cool, Humidity=High, Wind=Strong)

Dr.YanjunQi/UVACS

!![P̂( ′a1 |c* )⋅⋅⋅P̂( ′ap |c* )]P̂(c* )>[P̂( ′a1 |c)⋅⋅⋅P̂( ′ap |c)]P̂(c)

12/6/18 44

Page 45: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Testing the NBC Model

•  Test Phase

–  Given a new instance, x’=(Outlook=Sunny, Temperature=Cool, Humidity=High, Wind=Strong)

Dr.YanjunQi/UVACS

!![P̂( ′a1 |c* )⋅⋅⋅P̂( ′ap |c* )]P̂(c* )>[P̂( ′a1 |c)⋅⋅⋅P̂( ′ap |c)]P̂(c)

12/6/18 45

Page 46: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Testing the NBC Model

•  Test Phase –  Given a new instance, x’=(Outlook=Sunny, Temperature=Cool, Humidity=High, Wind=Strong)–  Look up in conditional-prob tables

P(Outlook=Sunny|Play=No) = 3/5P(Temperature=Cool|Play==No) = 1/5P(Huminity=High|Play=No) = 4/5P(Wind=Strong|Play=No) = 3/5P(Play=No) = 5/14

P(Outlook=Sunny|Play=Yes) = 2/9P(Temperature=Cool|Play=Yes) = 3/9P(Huminity=High|Play=Yes) = 3/9P(Wind=Strong|Play=Yes) = 3/9P(Play=Yes) = 9/14

12/6/18

Dr.YanjunQi/UVACS

!![P̂( ′a1 |c* )⋅⋅⋅P̂( ′ap |c* )]P̂(c* )>[P̂( ′a1 |c)⋅⋅⋅P̂( ′ap |c)]P̂(c)

46

Page 47: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Testing the NBC Model

•  Test Phase –  Given a new instance, x’=(Outlook=Sunny, Temperature=Cool, Humidity=High, Wind=Strong)–  Look up in conditional-prob tables

–  MAP rule

P(Outlook=Sunny|Play=No) = 3/5P(Temperature=Cool|Play==No) = 1/5P(Huminity=High|Play=No) = 4/5P(Wind=Strong|Play=No) = 3/5P(Play=No) = 5/14

P(Outlook=Sunny|Play=Yes) = 2/9P(Temperature=Cool|Play=Yes) = 3/9P(Huminity=High|Play=Yes) = 3/9P(Wind=Strong|Play=Yes) = 3/9P(Play=Yes) = 9/14

P(Yes|x’): [P(Sunny|Yes)P(Cool|Yes)P(High|Yes)P(Strong|Yes)]P(Play=Yes) = 0.0053 P(No|x’): [P(Sunny|No) P(Cool|No)P(High|No)P(Strong|No)]P(Play=No) = 0.0206

Given the fact P(Yes|x’) < P(No|x’), we label x’ to be “No”.

12/6/18

Dr.YanjunQi/UVACS

!![P̂( ′a1 |c* )⋅⋅⋅P̂( ′ap |c* )]P̂(c* )>[P̂( ′a1 |c)⋅⋅⋅P̂( ′ap |c)]P̂(c)

47

Page 48: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

WHY ? Naïve Bayes Assumption

•  P(cj)–  Canbeestimatedfromthefrequencyofclassesinthetrainingexamples.

•  P(x1,x2,…,xp|cj)– O(|X1|.|X2|.|X3|….|Xp|.|C|)parameters–  Couldonlybeestimatedifavery,verylargenumberoftrainingexampleswasavailable.

NaïveBayesConditionalIndependenceAssumption:•  Assumethattheprobabilityofobservingtheconjunctionof

attributesisequaltotheproductoftheindividualprobabilitiesP(xi|cj).

48

Ifnonaïveassumption

12/6/18

Dr.YanjunQi/UVACS

AdaptFromManning’textCattutorial

Page 49: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

WHY ? Naïve Bayes Assumption •  P(cj)

–  Canbeestimatedfromthefrequencyofclassesinthetrainingexamples.

•  P(x1,x2,…,xp|cj)–  O(|X1|.|X2|.|X3|….|Xp|.|C|)parameters–  Couldonlybeestimatedifavery,verylargenumberoftrainingexampleswasavailable.

•  P(xk|cj)

–  O([|X1|+|X2|+|X3|….+|Xp|].|C|)parameters–  AssumethattheprobabilityofobservingtheconjunctionofattributesisequaltotheproductoftheindividualprobabilitiesP(xi|cj).

49 12/6/18

Dr.YanjunQi/UVACS

Naïve

NotNaïve

Page 50: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

WHY ? Naïve Bayes Assumption •  P(cj)

–  Canbeestimatedfromthefrequencyofclassesinthetrainingexamples.

•  P(x1,x2,…,xp|cj)–  O(|X1|.|X2|.|X3|….|Xp|.|C|)parameters–  Couldonlybeestimatedifavery,verylargenumberoftrainingexampleswasavailable.

•  P(xk|cj)

–  O([|X1|+|X2|+|X3|….+|Xp|].|C|)parameters–  AssumethattheprobabilityofobservingtheconjunctionofattributesisequaltotheproductoftheindividualprobabilitiesP(xi|cj).

50 12/6/18

Dr.YanjunQi/UVACS

Naïve

NotNaïve

Page 51: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Challenges during Learning (training) the NBC Model

C

X1 X2 X5 X3 X4 X6

51

12/6/18

Dr.YanjunQi/UVACS

C=Flu

X1 X2 X5 X3 X4 X6=Muscle-ache

Forinstance:

Page 52: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

•  What if we have seen no training cases where patient had no flu and muscle aches?

•  Zero probabilities cannot be conditioned away, no matter the other evidence!

P̂(X6 = t |C = not_flu)=

N(X6 = t ,C = nf )N(C = nf ) =0

??= argmaxc P̂(c) P̂(xi |c)i∏12/6/18 52

C=Flu

X1 X2 X5 X3 X4 X6=Muscle-ache

Forinstance:

Dr.YanjunQi/UVACS

Page 53: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

12/6/18

Dr.YanjunQi/UVACS

53

Page 54: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Smoothing to Avoid Overfitting

kcCNcCxXN

cxPj

jiiji +=

+===

)(1),(

)|(ˆ

#ofvaluesof feature Xi

12/6/18 54

Tomakesum_i(P(xi|Cj)=1

Dr.YanjunQi/UVACS

AdaptFromManning’textCattutorial

i

Page 55: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Smoothing to Avoid Overfitting

P̂(xi |c j )=

N(Xi = xi ,C = c j )+1N(C = c j )+ki

•  Somewhat more subtle version

#ofvaluesof Xi

mcCNmpcCxXN

cxPj

kijkiijki +=

+===

)(),(

)|(ˆ ,,,

overallfractionindatawhereXi=xi,k

extentof“smoothing” 55 12/6/18

Dr.YanjunQi/UVACS

Page 56: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Summary: Generative Bayes Classifier

Task: Classify a new instance X based on a tuple of attribute values into one of the classes X = X1,X2,…,Xp

cMAP = argmaxcj∈C

P(cj | x1, x2,…, xp )

= argmaxcj∈C

P(x1, x2,…, xp | cj )P(cj )P(x1, x2,…, xp )

= argmaxcj∈C

P(x1, x2,…, xp | cj )P(cj )

56

MAP=MaximumAPosteriori

12/6/18

Dr.YanjunQi/UVACS

AdaptFromCarols’probtutorial

Page 57: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Today:GenerativeBayesClassifiers

ü BayesClassifier§  GenerativeBayesClassifier

ü NaïveBayesClassifierü GaussianBayesClassifiers

§  Gaussiandistribution§  NaïveGaussianBC§  Not-naïveGaussianBCèLDA,QDA

12/6/18

Dr.YanjunQi/UVACS

57

Page 58: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

GaussianDistribution

Courtesy:http://research.microsoft.com/~cmbishop/PRML/index.htm

CovarianceMatrixMean12/6/18

Dr.YanjunQi/UVACS

58

( )2~ ,X N µ σ

Page 59: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Example: the Bivariate Normal distribution

p( !x) = f x1,x2( ) = 1

2π( ) Σ 1/2 e−1

2!x−!µ( )T Σ−1 !x−

!µ( )

with

!µ =

µ1

µ2

⎣⎢⎢

⎦⎥⎥

22 1 2

22 22 22 2 2

σ σ σ ρσ σσ σ ρσ σ σ

11 1 1

×1 1

⎡ ⎤⎡ ⎤Σ = = ⎢ ⎥⎢ ⎥

⎣ ⎦ ⎣ ⎦

and

( )2 2 2 222 12 1 2 1σ σ σ σ σ ρ11Σ = − = −

12/6/18

Dr.YanjunQi/UVACS

59

Page 60: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Scatter Plots of data from the bivariate Normal distribution

Dr.YanjunQi/UVACS

Page 61: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

HowtoEstimateGaussian:MLE

∑=

=n

iixn 1

•  In the 1D Gaussian case, we simply set the mean and the variance to the sample mean and the sample variance:

2

σ = 1n

2

( ix −µ)i=1

n

Dr.YanjunQi/UVACS

Page 62: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Dr.YanjunQi/UVACS

< X1, X2!, X p >~ N µ

"#,Σ( )

The p-multivariate Normal distribution

Page 63: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Gaussian Naïve Bayes Classifier

12/6/18

Dr.YanjunQi/UVACS

63

argmaxC

P(C | X) = argmaxC

P(X,C) = argmaxC

P(X |C)P(C)

ijji

ijji

ji

jij

jiij

cCcX

XcCXP

=

=

⎟⎟⎠

⎞⎜⎜⎝

⎛ −−==

whichfor examples of X values attribute of deviation standard :C whichfor examples of values attribute of (avearage) mean :

2)(

exp2

1)|(ˆ 2

2

σµ

σµ

σπ

P(X |C) = P(X1,X2, ⋅ ⋅ ⋅,Xp |C)= P(X1 | X2, ⋅ ⋅ ⋅,Xp,C)P(X2, ⋅ ⋅ ⋅,Xp |C)= P(X1 |C)P(X2, ⋅ ⋅ ⋅,Xp |C)= P(X1 |C)P(X2 |C) ⋅ ⋅ ⋅P(Xp |C)

NaïveBayesClassifier

Page 64: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Gaussian Naïve Bayes Classifier

12/6/18

Dr.YanjunQi/UVACS

64

argmaxC

P(C | X) = argmaxC

P(X,C) = argmaxC

P(X |C)P(C)

ijji

ijji

ji

jij

jiij

cCcX

XcCXP

=

=

⎟⎟⎠

⎞⎜⎜⎝

⎛ −−==

whichfor examples of X values attribute of deviation standard :C whichfor examples of values attribute of (avearage) mean :

2)(

exp2

1)|(ˆ 2

2

σµ

σµ

σπ

P(X |C) = P(X1,X2, ⋅ ⋅ ⋅,Xp |C)= P(X1 | X2, ⋅ ⋅ ⋅,Xp,C)P(X2, ⋅ ⋅ ⋅,Xp |C)= P(X1 |C)P(X2, ⋅ ⋅ ⋅,Xp |C)= P(X1 |C)P(X2 |C) ⋅ ⋅ ⋅P(Xp |C)

NaïveBayesClassifier

Page 65: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

65

Gaussian Naïve Bayes Classifier

•  Continuous-valued Input Attributes –  Conditional probability modeled with the normal distribution

–  Learning Phase: Output: normal distributions and

–  Test Phase: •  Calculate conditional probabilities with all the normal distributions •  Apply the MAP rule to make a decision

P̂(Xj |C = ci ) =1

2πσ ji

exp −(X j−µ ji )

2

2σ ji2

"

#$$

%

&''

µ ji : mean (avearage) of attribute values Xj of examples for which C = ciσ ji : standard deviation of attribute values X j of examples for which C = ci

for X = (X1, ⋅ ⋅ ⋅,Xp ), C = c1, ⋅ ⋅ ⋅,cLp× L

for !X = ( !X1, ⋅ ⋅ ⋅, !Xp )

P(C = ci ) i =1, ⋅ ⋅ ⋅,L

12/6/18

Dr.YanjunQi/UVACS

Page 66: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

66

Gaussian Naïve Bayes Classifier

•  Continuous-valued Input Attributes –  Conditional probability modeled with the normal distribution

–  Learning Phase: Output: normal distributions and

–  Test Phase: •  Calculate conditional probabilities with all the normal distributions •  Apply the MAP rule to make a decision

P̂(Xj |C = ci ) =1

2πσ ji

exp −(X j−µ ji )

2

2σ ji2

"

#$$

%

&''

µ ji : mean (avearage) of attribute values Xj of examples for which C = ciσ ji : standard deviation of attribute values X j of examples for which C = ci

for X = (X1, ⋅ ⋅ ⋅,Xp ), C = c1, ⋅ ⋅ ⋅,cLp× L

for !X = ( !X1, ⋅ ⋅ ⋅, !Xp )

P(C = ci ) i =1, ⋅ ⋅ ⋅,L

12/6/18

Dr.YanjunQi/UVACS

Page 67: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Today:GenerativeBayesClassifiers

ü BayesClassifier§  GenerativeBayesClassifier

ü NaïveBayesClassifierü GaussianBayesClassifiers

§  Gaussiandistribution§  NaïveGaussianBC§  Not-naïveGaussianBCèLDA,QDA

12/6/18

Dr.YanjunQi/UVACS

67

Page 68: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Dr.YanjunQi/UVACS

P(X1,X2, ⋅ ⋅ ⋅,Xp |C = cj ) = P(X1 |C)P(X2 |C) ⋅ ⋅ ⋅P(Xp |C)

=∏i

12πσ ji

exp −(X j−µ ji )

2

2σ ji2

$

%&&

'

())

Naïve

Σ_ ck = Λ _ ckDiagonalMatrixEachclass’covariancematrixisdiagonal

NaïveGaussianmeans?

Page 69: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

NotNaïveGaussianmeans?

12/6/18

Dr.YanjunQi/UVACS

69

P(X1,X2, ⋅ ⋅ ⋅,Xp |C = cj ) = P(X1 |C)P(X2 |C) ⋅ ⋅ ⋅P(Xp |C)

=∏i

12πσ ji

exp −(X j−µ ji )

2

2σ ji2

$

%&&

'

())

P(X1,X2, ⋅ ⋅ ⋅,Xp |C) =

Naïve

NotNaïve

12/6/18Σ_ ck = Λ _ ckDiagonalMatrix

Eachclass’covariancematrixisdiagonal

Page 70: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Today:GenerativeBayesClassifiers

ü GaussianBayesClassifiers

§  Gaussiandistribution§  NaïveGaussianBC§  Not-naïveGaussianBC§  LDA:LinearDiscriminantAnalysis§  QDA:QuadraticDiscriminantAnalysis

12/6/18

Dr.YanjunQi/UVACS

70

Page 71: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

(1)covariancematrixarethesameacrossclassesèLDA(LinearDiscriminantAnalysis)

12/6/18

Dr.YanjunQi/UVACS

71

Classk Classl Classk Classl

Eachclass’covariancematrixisthesame

Page 72: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

72

Visualization (three classes)

12/6/18

Dr.YanjunQi/UVACS

Page 73: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

12/6/18

Dr.YanjunQi/UVACS

73

!!

argmaxk

P(Ck |X )= argmaxk

P(X ,Ck )= argmaxk

P(X |Ck )P(Ck )= argmax

klog{P(X |Ck )P(Ck )}

Page 74: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

12/6/18

Dr.YanjunQi/UVACS

74

!!

argmaxk

P(Ck |X )= argmaxk

P(X ,Ck )= argmaxk

P(X |Ck )P(Ck )= argmax

klog{P(X |Ck )P(Ck )}

Page 75: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

12/6/18

Dr.YanjunQi/UVACS

75

!!log P(Ck |X )

P(Cl |X )= log P(X |Ck )

P(X |Cl )+ log P(Ck )

P(Cl )

Page 76: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

12/6/18

Dr.YanjunQi/UVACS

76

!!log P(Ck |X )

P(Cl |X )= log P(X |Ck )

P(X |Cl )+ log P(Ck )

P(Cl )

Theaboveisderivedfromthefollowing:

Page 77: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

12/6/18

Dr.YanjunQi/UVACS

77

!!log P(Ck |X )

P(Cl |X )= log P(X |Ck )

P(X |Cl )+ log P(Ck )

P(Cl )

Page 78: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

LDAClassificationRule(alsocalledasLineardiscriminantfunction:)-  Note

argmax

kP(Ck |X )= argmax

kP(X ,Ck )= argmax

kP(X |Ck )P(Ck )

12/6/18

Dr.YanjunQi/UVACS

78

Page 79: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Today:GenerativeBayesClassifiers

ü BayesClassifier§  GenerativeBayesClassifier

ü NaïveBayesClassifierü GaussianBayesClassifiers

§  Gaussiandistribution§  NaïveGaussianBC§  Not-naïveGaussianBCèLDA,QDA

12/6/18

Dr.YanjunQi/UVACS

79

Page 80: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

(2)Ifcovariancematrixarenotthesamee.g.èQDA(QuadraticDiscriminantAnalysis)

12/6/18

Dr.YanjunQi/UVACS

80

Page 81: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

(2)Ifcovariancematrixarenotthesamee.g.èQDA(QuadraticDiscriminantAnalysis)

12/6/18

Dr.YanjunQi/UVACS

81

Page 82: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

QDAvs.LDAonExpandedBasis

12/6/18

Dr.YanjunQi/UVACS

82

LDAwithquadraticbasisVersusQDA

Page 83: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

(3)RegularizedDiscriminantAnalysis

12/6/18

Dr.YanjunQi/UVACS

83

Page 84: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Anexample:GaussianBayesClassifier

12/6/18

Dr.YanjunQi/UVACS

84

Page 85: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

GaussianBayesClassifier

12/6/18

Dr.YanjunQi/UVACS

85

Page 86: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

GaussianBayesClassifier

RedTeam

BlueTeam

NaïveGaussianBayesClassifierisnotalinearclassifier!

Page 87: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

TodayRecap:GenerativeBayesClassifiers

ü BayesClassifier§  GenerativeBayesClassifier

ü NaïveBayesClassifierü GaussianBayesClassifiers

§  Gaussiandistribution§  NaïveGaussianBC§  Not-naïveGaussianBCèLDA,QDA

12/6/18

Dr.YanjunQi/UVACS

87

Page 88: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

Generative Bayes Classifier

classification

Prob. models p(X|C)

EPE with 0-1 loss è MAP Rule

Many options

Prob. Models’ Parameter

Task

Representation

Score Function

Search/Optimization

Models, Parameters

P(X1, ⋅ ⋅ ⋅,Xp |C)

argmaxk

P(C _ k | X) = argmaxk

P(X,C) = argmaxk

P(X |C)P(C)

P̂(Xj |C = ck ) =1

2πσ jk

exp −(X j−µ jk )

2

2σ jk2

"

#$$

%

&''

P(W1 = n1,...,Wv = nv | ck ) =N !

n1k !n2k !..nvk !θ1kn1kθ2k

n2k ..θvknvk

p(Wi = true | ck ) = pi,kBernoulliNaïve

GaussianNaive

Multinomial

Page 89: UVA CS 4501: Machine Learning Lecture 17: Generative Bayes ... · Machine Learning Lecture 17: Generative Bayes Classifiers Dr. Yanjun Qi University of Virginia Department of Computer

References

q Prof.AndrewMoore’sreviewtutorialq Prof.KeChenNBslidesq Prof.CarlosGuestrinrecitationslides

12/6/18

Dr.YanjunQi/UVACS

89