homework 3: solutions

28
Homework 3: Solutions CS4445/B12 Provided by: Kenneth J. Loomis

Upload: season

Post on 23-Feb-2016

92 views

Category:

Documents


5 download

DESCRIPTION

CS4445/B12 Provided by: Kenneth J. Loomis. Homework 3: Solutions. Topology of the Network. This is the naïve topology, we can easily construct the graph for this dataset. likes. genre. critics-reviews. rating. IMAX. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Homework 3: Solutions

Homework 3: Solutions

CS4445/B12Provided by: Kenneth J. Loomis

Page 2: Homework 3: Solutions

Topology of the Network• This is the naïve topology, we can easily construct the graph for this dataset.

likes

critics-

reviews

IMAXgenre rating

• Then we need to calculate the conditional probability tables for each of the nodes in this network.• This will be shown in three steps for each node:1. Build a frequency table2. Add 1 to account for “fake” instances that prevent zero probability.3. Convert the frequency table to a conditional probability table.

Page 3: Homework 3: Solutions

Likes: Calculate Frequencieslikes

critics-

reviews

IMAXgenre rating

instance genre critics-reviews rating IMAX likes1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no3 comedy neutral R FALSE no12 action thumbs-down PG-13 TRUE no14 action neutral R TRUE no4 comedy thumbs-down PG-13 FALSE yes5 comedy neutral PG-13 TRUE yes6 drama thumbs-up R FALSE yes7 drama thumbs-down PG-13 TRUE yes8 drama neutral R TRUE yes9 drama thumbs-up PG-13 FALSE yes10 action neutral R FALSE yes11 action thumbs-down PG-13 FALSE yes13 action neutral PG-13 FALSE yes

Frequency Tableparents likes

- no yes- 5 9

• Notice that there are no parents for this node.

Page 4: Homework 3: Solutions

Likes: Include “fake” instances

likes

critics-

reviews

IMAXgenre rating

instance genre critics-reviews rating IMAX likes1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no3 comedy neutral R FALSE no12 action thumbs-down PG-13 TRUE no14 action neutral R TRUE no4 comedy thumbs-down PG-13 FALSE yes5 comedy neutral PG-13 TRUE yes6 drama thumbs-up R FALSE yes7 drama thumbs-down PG-13 TRUE yes8 drama neutral R TRUE yes9 drama thumbs-up PG-13 FALSE yes10 action neutral R FALSE yes11 action thumbs-down PG-13 FALSE yes13 action neutral PG-13 FALSE yes

Frequency Tableparents likes

- no yes- 5+1 9+1

• Add 1 to each of the frequency counts.

Page 5: Homework 3: Solutions

Likes: Convert to CPTlikes

critics-

reviews

IMAXgenre rating

instance genre critics-reviews rating IMAX likes1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no3 comedy neutral R FALSE no12 action thumbs-down PG-13 TRUE no14 action neutral R TRUE no4 comedy thumbs-down PG-13 FALSE yes5 comedy neutral PG-13 TRUE yes6 drama thumbs-up R FALSE yes7 drama thumbs-down PG-13 TRUE yes8 drama neutral R TRUE yes9 drama thumbs-up PG-13 FALSE yes10 action neutral R FALSE yes11 action thumbs-down PG-13 FALSE yes13 action neutral PG-13 FALSE yes

CPTparents likes

- no yes-

• Notice that we add two “fake” instances, so we add 2 to the total number of instance:

Page 6: Homework 3: Solutions

Genre: Calculate Frequencieslikes

critics-

reviews

IMAXgenre rating

• Notice that there is a parent for this node.instance genre critics-reviews rating IMAX likes4 action thumbs-down PG-13 TRUE no5 action neutral R TRUE no12 action neutral R FALSE yes13 action thumbs-down PG-13 FALSE yes14 action neutral PG-13 FALSE yes1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no3 comedy neutral R FALSE no6 comedy thumbs-down PG-13 FALSE yes7 comedy neutral PG-13 TRUE yes8 drama thumbs-up R FALSE yes9 drama thumbs-down PG-13 TRUE yes10 drama neutral R TRUE yes11 drama thumbs-up PG-13 FALSE yes

Frequency Tableparent

s genre

likes action comedy drama

no 2 3 0yes 3 2 4

Page 7: Homework 3: Solutions

Genre: Include “fake” instances

likes

critics-

reviews

IMAXgenre rating

• Add 1 to each of the frequency counts.instance genre critics-reviews rating IMAX likes4 action thumbs-down PG-13 TRUE no5 action neutral R TRUE no12 action neutral R FALSE yes13 action thumbs-down PG-13 FALSE yes14 action neutral PG-13 FALSE yes1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no3 comedy neutral R FALSE no6 comedy thumbs-down PG-13 FALSE yes7 comedy neutral PG-13 TRUE yes8 drama thumbs-up R FALSE yes9 drama thumbs-down PG-13 TRUE yes10 drama neutral R TRUE yes11 drama thumbs-up PG-13 FALSE yes

Frequency Tableparent

s genre

likes action comedy drama

no 2+1 3+1 0+1yes 3+1 2+1 4+1

Page 8: Homework 3: Solutions

Genre: Convert to CPTlikes

critics-

reviews

IMAXgenre rating

• Notice that there are • 5+3=8 “noes” and • 9+3=12 “yesses”.

instance genre critics-reviews rating IMAX likes4 action thumbs-down PG-13 TRUE no5 action neutral R TRUE no12 action neutral R FALSE yes13 action thumbs-down PG-13 FALSE yes14 action neutral PG-13 FALSE yes1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no3 comedy neutral R FALSE no6 comedy thumbs-down PG-13 FALSE yes7 comedy neutral PG-13 TRUE yes8 drama thumbs-up R FALSE yes9 drama thumbs-down PG-13 TRUE yes10 drama neutral R TRUE yes11 drama thumbs-up PG-13 FALSE yes

CPTparent

s genre

likes action comedy drama

no

yes

Page 9: Homework 3: Solutions

Critics-Reviews: Calculate Frequencies

likes

critics-

reviews

IMAXgenre rating

• Notice that there is a parent for this node.Frequency Table

parents critics-reviews

likes neutral

thumbs-down

thumbs-up

no 2 1 2yes 4 3 2

instance genre critics-reviews rating IMAX likes5 action neutral R TRUE no3 comedy neutral R FALSE no12 action neutral R FALSE yes14 action neutral PG-13 FALSE yes7 comedy neutral PG-13 TRUE yes10 drama neutral R TRUE yes4 action thumbs-down PG-13 TRUE no13 action thumbs-down PG-13 FALSE yes6 comedy thumbs-down PG-13 FALSE yes9 drama thumbs-down PG-13 TRUE yes1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no8 drama thumbs-up R FALSE yes11 drama thumbs-up PG-13 FALSE yes

Page 10: Homework 3: Solutions

Critics-Reviews: Include “fake” instances

likes

critics-

reviews

IMAXgenre rating

• Add 1 to each of the frequency counts.Frequency Table

parents critics-reviews

likes neutral

thumbs-down

thumbs-up

no 2+1 1+1 2+1yes 4+1 3+1 2+1

instance genre critics-reviews rating IMAX likes5 action neutral R TRUE no3 comedy neutral R FALSE no12 action neutral R FALSE yes14 action neutral PG-13 FALSE yes7 comedy neutral PG-13 TRUE yes10 drama neutral R TRUE yes4 action thumbs-down PG-13 TRUE no13 action thumbs-down PG-13 FALSE yes6 comedy thumbs-down PG-13 FALSE yes9 drama thumbs-down PG-13 TRUE yes1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no8 drama thumbs-up R FALSE yes11 drama thumbs-up PG-13 FALSE yes

Page 11: Homework 3: Solutions

Critics-Reviews: Convert to CPTlikes

critics-

reviews

IMAXgenre rating

• Notice that there are • 5+3=8 “noes” and • 9+3=12 “yesses”.

CPTparent

s critics-reviews

likes neutral

thumbs-down

thumbs-up

no

yes

instance genre critics-reviews rating IMAX likes5 action neutral R TRUE no3 comedy neutral R FALSE no12 action neutral R FALSE yes14 action neutral PG-13 FALSE yes7 comedy neutral PG-13 TRUE yes10 drama neutral R TRUE yes4 action thumbs-down PG-13 TRUE no13 action thumbs-down PG-13 FALSE yes6 comedy thumbs-down PG-13 FALSE yes9 drama thumbs-down PG-13 TRUE yes1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no8 drama thumbs-up R FALSE yes11 drama thumbs-up PG-13 FALSE yes

Page 12: Homework 3: Solutions

Rating: Calculate Frequencies

likes

critics-

reviews

IMAXgenre rating

• Notice that there is a parent for this node.Frequency Table

parents Rating

likes PG-13 Rno 1 4yes 6 3

instance genre critics-reviews rating IMAX likes4 action thumbs-down PG-13 TRUE no6 comedy thumbs-down PG-13 FALSE yes7 comedy neutral PG-13 TRUE yes9 drama thumbs-down PG-13 TRUE yes11 drama thumbs-up PG-13 FALSE yes13 action thumbs-down PG-13 FALSE yes14 action neutral PG-13 FALSE yes1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no3 comedy neutral R FALSE no5 action neutral R TRUE no8 drama thumbs-up R FALSE yes10 drama neutral R TRUE yes12 action neutral R FALSE yes

Page 13: Homework 3: Solutions

Rating : Include “fake” instances

likes

critics-

reviews

IMAXgenre rating

• Add 1 to each of the frequency counts.Frequency Table

parents Rating

likes PG-13 Rno 1+1 4+1yes 6+1 3+1

instance genre critics-reviews rating IMAX likes4 action thumbs-down PG-13 TRUE no6 comedy thumbs-down PG-13 FALSE yes7 comedy neutral PG-13 TRUE yes9 drama thumbs-down PG-13 TRUE yes11 drama thumbs-up PG-13 FALSE yes13 action thumbs-down PG-13 FALSE yes14 action neutral PG-13 FALSE yes1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no3 comedy neutral R FALSE no5 action neutral R TRUE no8 drama thumbs-up R FALSE yes10 drama neutral R TRUE yes12 action neutral R FALSE yes

Page 14: Homework 3: Solutions

Rating : Convert to CPTlikes

critics-

reviews

IMAXgenre rating

• Notice that there are • 5+2=7 “noes” and • 9+2=11 “yesses”.

CPTparent

s Ratinglikes PG-13 Rno

yes

instance genre critics-reviews rating IMAX likes4 action thumbs-down PG-13 TRUE no6 comedy thumbs-down PG-13 FALSE yes7 comedy neutral PG-13 TRUE yes9 drama thumbs-down PG-13 TRUE yes11 drama thumbs-up PG-13 FALSE yes13 action thumbs-down PG-13 FALSE yes14 action neutral PG-13 FALSE yes1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no3 comedy neutral R FALSE no5 action neutral R TRUE no8 drama thumbs-up R FALSE yes10 drama neutral R TRUE yes12 action neutral R FALSE yes

Page 15: Homework 3: Solutions

IMAX: Calculate Frequencieslikes

critics-

reviews

IMAXgenre rating

• Notice that there is a parent for this node.Frequency Table

parents IMAX

likes FALSE TRUEno 2 3yes 6 3

instance genre critics-reviews rating IMAX likes1 comedy thumbs-up R FALSE no3 comedy neutral R FALSE no6 comedy thumbs-down PG-13 FALSE yes8 drama thumbs-up R FALSE yes11 drama thumbs-up PG-13 FALSE yes12 action neutral R FALSE yes13 action thumbs-down PG-13 FALSE yes14 action neutral PG-13 FALSE yes2 comedy thumbs-up R TRUE no4 action thumbs-down PG-13 TRUE no5 action neutral R TRUE no7 comedy neutral PG-13 TRUE yes9 drama thumbs-down PG-13 TRUE yes10 drama neutral R TRUE yes

Page 16: Homework 3: Solutions

IMAX: Include “fake” instances

likes

critics-

reviews

IMAXgenre rating

• Add 1 to each of the frequency counts.Frequency Table

parents IMAX

likes FALSE TRUEno 2+1 3+1yes 6+1 3+1

instance genre critics-reviews rating IMAX likes1 comedy thumbs-up R FALSE no3 comedy neutral R FALSE no6 comedy thumbs-down PG-13 FALSE yes8 drama thumbs-up R FALSE yes11 drama thumbs-up PG-13 FALSE yes12 action neutral R FALSE yes13 action thumbs-down PG-13 FALSE yes14 action neutral PG-13 FALSE yes2 comedy thumbs-up R TRUE no4 action thumbs-down PG-13 TRUE no5 action neutral R TRUE no7 comedy neutral PG-13 TRUE yes9 drama thumbs-down PG-13 TRUE yes10 drama neutral R TRUE yes

Page 17: Homework 3: Solutions

IMAX: Convert to CPTlikes

critics-

reviews

IMAXgenre rating

• Notice that there are • 5+2=7 “noes” and • 9+2=11 “yesses”.

CPTparent

s IMAXlikes FALSE TRUEno

yes

instance genre critics-reviews rating IMAX likes1 comedy thumbs-up R FALSE no3 comedy neutral R FALSE no6 comedy thumbs-down PG-13 FALSE yes8 drama thumbs-up R FALSE yes11 drama thumbs-up PG-13 FALSE yes12 action neutral R FALSE yes13 action thumbs-down PG-13 FALSE yes14 action neutral PG-13 FALSE yes2 comedy thumbs-up R TRUE no4 action thumbs-down PG-13 TRUE no5 action neutral R TRUE no7 comedy neutral PG-13 TRUE yes9 drama thumbs-down PG-13 TRUE yes10 drama neutral R TRUE yes

Page 18: Homework 3: Solutions

Topology of the Network

• This is the network with the Conditional Probability Tableslikes

critics-

reviews

IMAXgenre rating

likesno yes

parents genrelikes action comedy drama

no

yes

parents IMAX

likes FALSE TRUE

no

yes

parents Ratinglikes PG-13 R

no

yes

parents critics-reviewslikes neutral thumbs-

downthumbs-

up

no

yes

Page 19: Homework 3: Solutions

Classification

likes

critics-

reviews

IMAXgenre rating

likesno yes

parents genrelikes action comedy drama

no

yes

parents IMAX

likes FALSE TRUE

no

yes

parents Ratinglikes PG-13 R

no

yes

parents critics-reviewslikes neutral thumbs-

downthumbs-

up

no

yes

• Classify• genre = action,• critics-reviews =

neutral,• rating = R, • IMAX = TRUE,• likes = ?

Page 20: Homework 3: Solutions

Classification

• Classify• genre = action,• critics-reviews =

neutral,• rating = R, • IMAX = TRUE,• likes = ?

• Recall how we classify using a Bayesian network.

• Find the argument (yes or no) that maximizes the probability.

argmax ( Pr(yes), Pr(no) )= argmax ( Pr (genre = action, critics-reviews = neutral, rating = R, IMAX = TRUE | likes = yes ),

Pr (genre = action, critics-reviews = neutral, rating = R, IMAX = TRUE | likes = no )

= argmax ( ( Pr (genre = action | likes = yes) * Pr(critics-reviews = neutral | likes = yes) *

Pr (rating = R | likes = yes) * Pr (IMAX = TRUE | likes = yes) * Pr (likes = yes) ) ,

( Pr (genre = action | likes = no) * Pr (critics-reviews = neutral | likes = no ) *

Pr (rating = R | likes = no) * Pr (IMAX = TRUE | likes = no ) * Pr (likes= no) ) )

Page 21: Homework 3: Solutions

Classification

likes

critics-

reviews

IMAXgenre rating

likesno yes

parents genrelikes action comedy drama

no

yes

parents IMAX

likes FALSE TRUE

no

yes

parents Ratinglikes PG-13 R

no

yes

parents critics-reviewslikes neutral thumbs-

downthumbs-

up

no

yes

Pr(yes) = Pr (genre = action, critics-reviews = neutral, rating = R, IMAX = TRUE | likes = yes )= Pr (genre = action | likes = yes) * Pr(critics-reviews = neutral | likes = yes) *

Pr (rating = R | likes = yes) * Pr (IMAX = TRUE | likes = yes) * Pr (likes = yes)

=

Page 22: Homework 3: Solutions

Classification

likes

critics-

reviews

IMAXgenre rating

likesno yes

parents genrelikes action comedy drama

no

yes

parents IMAX

likes FALSE TRUE

no

yes

parents Ratinglikes PG-13 R

no

yes

parents critics-reviewslikes neutral thumbs-

downthumbs-

up

no

yes

Pr(no) = Pr (genre = action, critics-reviews = neutral, rating = R, IMAX = TRUE | likes = no )= Pr (genre = action | likes = no) * Pr(critics-reviews = neutral | likes = no) *

Pr (rating = R | likes = no) * Pr (IMAX = TRUE | likes = no) * Pr (likes = no)

= * * * ≈ 0.021524

Page 23: Homework 3: Solutions

Classification

Classified as• genre = action,• critics-reviews =

neutral,• rating = R, • IMAX = TRUE,• likes = no

Thus we have the following: argmax ( Pr(yes), Pr(no) ) = argmax ( 0.008609,

0.021524)

And the highest probability is for likes = no.

Page 24: Homework 3: Solutions

Classifying instances with missing values

Notice we have missing values this time… We could calculate the probability of the missing values thusly:Pr(IMAX = ? | likes = no)= Pr(IMAX = FALSE | likes = no) + Pr(IMAX = TRUE | likes = no)= Since this will always be 1 (which will not alter the product we can ignore them).argmax ( Pr(yes), Pr(no) )

= argmax ( Pr (genre = action, rating = R | likes = yes), Pr (genre = action, rating = R | likes = no)) = argmax ( ( Pr (genre = action | likes = yes) * Pr (rating = R | likes = yes) * Pr (likes = yes) ) ,

( Pr (genre = action | likes = no) * Pr (rating = R | likes = no) * Pr (likes= no) ) )

= argmax ( , = ) = argmax ( 0.056818, 0.100446 )

Hence this instance is classified as likes = no

Classify• genre =

action,• critics-reviews

= ?,• rating = R, • IMAX = ?,• likes = ?

Page 25: Homework 3: Solutions

CPT: Critics-Reviewslikes

critics-

reviews

IMAX

genre

rating

• Notice that we have a two parents for critics-reviews:• likes• genre

• The conditional probability table must reflect this.

Page 26: Homework 3: Solutions

Critics-Reviews: Calculate Frequencies

Frequency Tableparents Critics-Reviews

Likes genre neutral thumbs-down

thumbs-up

no action 1 1 0no comed

y 1 2 0no drama 0 0 0yes action 2 1 0yes comed

y 1 1 0yes drama 1 1 2

instance genre critics-reviews rating IMAX likes5 action neutral R TRUE no4 action thumbs-down PG-13 TRUE no3 comedy neutral R FALSE no1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no12 action neutral R FALSE yes14 action neutral PG-13 FALSE yes13 action thumbs-down PG-13 FALSE yes7 comedy neutral PG-13 TRUE yes6 comedy thumbs-down PG-13 FALSE yes10 drama neutral R TRUE yes9 drama thumbs-down PG-13 TRUE yes8 drama thumbs-up R FALSE yes11 drama thumbs-up PG-13 FALSE yes

Ordered from left-to-right, top-to-bottom Notice that we have 2x3 number of possible parent values.

Page 27: Homework 3: Solutions

Critics-Reviews: Include “fake” instances

Frequency Tableparents Critics-Reviews

likes genre neutral thumbs-down

thumbs-up

no action 1+1 1+1 0+1no comed

y 1+1 2+1 0+1no drama 0+1 0+1 0+1yes action 2+1 1+1 0+1yes comed

y 1+1 1+1 0+1yes drama 1+1 1+1 2+1

instance genre critics-reviews rating IMAX likes5 action neutral R TRUE no4 action thumbs-down PG-13 TRUE no3 comedy neutral R FALSE no1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no12 action neutral R FALSE yes14 action neutral PG-13 FALSE yes13 action thumbs-down PG-13 FALSE yes7 comedy neutral PG-13 TRUE yes6 comedy thumbs-down PG-13 FALSE yes10 drama neutral R TRUE yes9 drama thumbs-down PG-13 TRUE yes8 drama thumbs-up R FALSE yes11 drama thumbs-up PG-13 FALSE yes

Ordered from left-to-right, top-to-bottom Add 1 to every recorded frequency.

Page 28: Homework 3: Solutions

Critics-Reviews: Convert to CPT

CPT

parents Critics-Reviews

Likes genre neutral thumbs-down

thumbs-up

no action

no comedy

no drama

yes action

yes comedy

yes drama

instance genre critics-reviews rating IMAX likes5 action neutral R TRUE no4 action thumbs-down PG-13 TRUE no3 comedy neutral R FALSE no1 comedy thumbs-up R FALSE no2 comedy thumbs-up R TRUE no12 action neutral R FALSE yes14 action neutral PG-13 FALSE yes13 action thumbs-down PG-13 FALSE yes7 comedy neutral PG-13 TRUE yes6 comedy thumbs-down PG-13 FALSE yes10 drama neutral R TRUE yes9 drama thumbs-down PG-13 TRUE yes8 drama thumbs-up R FALSE yes11 drama thumbs-up PG-13 FALSE yes

Ordered from left-to-right, top-to-bottom