Upload
season
View
85
Download
5
Tags:
Embed Size (px)
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
Citation preview
Homework 3: Solutions
CS4445/B12Provided by: Kenneth J. Loomis
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.
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.
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.
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:
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
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
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
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
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
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
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
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
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
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
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
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
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
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 = ?
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) ) )
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)
=
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
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.
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 = ?
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.
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.
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.
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