Data Mining 2020 Bayesian Networks (1) Ad Feelders Universiteit - - PowerPoint PPT Presentation

data mining 2020 bayesian networks 1
SMART_READER_LITE
LIVE PREVIEW

Data Mining 2020 Bayesian Networks (1) Ad Feelders Universiteit - - PowerPoint PPT Presentation

Data Mining 2020 Bayesian Networks (1) Ad Feelders Universiteit Utrecht Ad Feelders ( Universiteit Utrecht ) Data Mining 1 / 49 Do you like noodles? Do you like noodles? Race Gender Yes No Black Male 10 40 Female 30 20 White


slide-1
SLIDE 1

Data Mining 2020 Bayesian Networks (1)

Ad Feelders

Universiteit Utrecht

Ad Feelders ( Universiteit Utrecht ) Data Mining 1 / 49

slide-2
SLIDE 2

Do you like noodles?

Do you like noodles? Race Gender Yes No Black Male 10 40 Female 30 20 White Male 100 100 Female 120 80

Ad Feelders ( Universiteit Utrecht ) Data Mining 2 / 49

slide-3
SLIDE 3

Do you like noodles? Undirected

G R A

G ⊥ ⊥ R | A Strange: Gender and Race are prior to Answer, but this model says they are independent given Answer!

Ad Feelders ( Universiteit Utrecht ) Data Mining 3 / 49

slide-4
SLIDE 4

Do you like noodles?

Marginal table for Gender and Race: Race Gender Black White Male 50 200 Female 50 200 From this table we conclude that Race and Gender are independent in the data. cpr(G,R)= 1

Ad Feelders ( Universiteit Utrecht ) Data Mining 4 / 49

slide-5
SLIDE 5

Do you like noodles?

Table for Gender and Race given Answer=yes: Race Gender Black White Male 10 100 Female 30 120 cpr(G,R) = 0.4 Table for Gender and Race given Answer=no: Race Gender Black White Male 40 100 Female 20 80 cpr(G,R)=1.6 From these tables we conclude that Race and Gender are dependent given Answer.

Ad Feelders ( Universiteit Utrecht ) Data Mining 5 / 49

slide-6
SLIDE 6

Do you like noodles? Directed

G R A

G ⊥ ⊥ R, G ⊥ ⊥ R |A Gender and Race are marginally independent (but dependent given Answer).

Ad Feelders ( Universiteit Utrecht ) Data Mining 6 / 49

slide-7
SLIDE 7

Explaining away

S A L

Smoking (S) and asbestos exposure (A) are independent, but become dependent if we observe that someone has lung cancer (L). If we observe L, this raises the probability of both S and A. If we subsequently observe S, then the probability of A drops (explaining away effect).

Ad Feelders ( Universiteit Utrecht ) Data Mining 7 / 49

slide-8
SLIDE 8

Directed Independence Graphs

G = (K, E), K is a set of vertices and E is a set of edges with ordered pairs of vertices. No directed cycles (DAG) parent/child ancestor/descendant ancestral set Because G is a DAG, there exists a complete ordering of the vertices that is respected in the graph (edges point from lower ordered to higher

  • rdered nodes).

Ad Feelders ( Universiteit Utrecht ) Data Mining 8 / 49

slide-9
SLIDE 9

Parents Of Node i: pa(i)

i

Ad Feelders ( Universiteit Utrecht ) Data Mining 9 / 49

slide-10
SLIDE 10

Ancestors Of Node i: an(i)

i

Ad Feelders ( Universiteit Utrecht ) Data Mining 10 / 49

slide-11
SLIDE 11

Ancestral Set Of Node i: an+(i)

i

Ad Feelders ( Universiteit Utrecht ) Data Mining 11 / 49

slide-12
SLIDE 12

Children Of Node i: ch(i)

i

Ad Feelders ( Universiteit Utrecht ) Data Mining 12 / 49

slide-13
SLIDE 13

Descendants Of Node i: de(i)

i

Ad Feelders ( Universiteit Utrecht ) Data Mining 13 / 49

slide-14
SLIDE 14

Construction of DAG

Suppose that prior knowledge tells us the variables can be labeled X1, X2, . . . , Xk such that Xi is prior to Xi+1. (for example: causal or temporal ordering) Corresponding to this ordering we can use the product rule to factorize the joint distribution of X1, X2, . . . , Xk as P(X) = P(X1)P(X2 | X1) · · · P(Xk | Xk−1, Xk−2, . . . , X1) Note that:

1 This is an identity of probability theory, no independence assumptions

have been made yet!

2 The joint probability of any initial segment X1, X2, . . . , Xj (1 ≤ j ≤ k)

is given by the corresponding initial segment of the factorization.

Ad Feelders ( Universiteit Utrecht ) Data Mining 14 / 49

slide-15
SLIDE 15

Constructing a DAG from pairwise independencies

Starting from the complete graph (containing arrows i → j for all i < j) an arrow from i to j is removed if P(Xj | Xj−1, . . . , X1) does not depend

  • n Xi, in other words, if

j ⊥ ⊥ i | {1, . . . , j} \ {i, j} More loosely j ⊥ ⊥ i | prior variables Compare this to pairwise independence j ⊥ ⊥ i | rest in undirected independence graphs.

Ad Feelders ( Universiteit Utrecht ) Data Mining 15 / 49

slide-16
SLIDE 16

Construction Of DAG

1 2 3 4

P(X) = P(X1)P(X2|X1)P(X3|X1, X2)P(X4|X1, X2, X3) Suppose the following independencies are given:

1 X1 ⊥

⊥ X2

2 X4 ⊥

⊥ X3|(X1, X2)

3 X1 ⊥

⊥ X3|X2

Ad Feelders ( Universiteit Utrecht ) Data Mining 16 / 49

slide-17
SLIDE 17

Construction Of DAG

1 2 3 4

P(X) = P(X1) P(X2|X1)

  • P(X2)

P(X3|X1, X2)P(X4|X1, X2, X3)

1 If X1 ⊥

⊥ X2, then P(X2|X1) = P(X2). The edge 1 → 2 is removed.

Ad Feelders ( Universiteit Utrecht ) Data Mining 17 / 49

slide-18
SLIDE 18

Construction Of DAG

1 2 3 4

P(X) = P(X1)P(X2)P(X3|X1, X2)P(X4|X1, X2, X3)

Ad Feelders ( Universiteit Utrecht ) Data Mining 18 / 49

slide-19
SLIDE 19

Construction Of DAG

1 2 3 4

P(X) = P(X1)P(X2)P(X3|X1, X2) P(X4|X1, X2, X3)

  • P(X4|X1,X2)

2 If X4 ⊥

⊥ X3|(X1, X2), then P(X4|X1, X2, X3) = P(X4|X1, X2). The edge 3 → 4 is removed.

Ad Feelders ( Universiteit Utrecht ) Data Mining 19 / 49

slide-20
SLIDE 20

Construction Of DAG

1 2 3 4

P(X) = P(X1)P(X2)P(X3|X1, X2)P(X4|X1, X2)

Ad Feelders ( Universiteit Utrecht ) Data Mining 20 / 49

slide-21
SLIDE 21

Construction Of DAG

1 2 3 4

P(X) = P(X1)P(X2) P(X3|X1, X2)

  • P(X3|X2)

P(X4|X1, X2)

3 If X1 ⊥

⊥ X3|X2, then P(X3|X1, X2) = P(X3|X2) The edge 1 → 3 is removed.

Ad Feelders ( Universiteit Utrecht ) Data Mining 21 / 49

slide-22
SLIDE 22

Construction Of DAG

We end up with this independence graph and corresponding factorization:

1 2 3 4

P(X) = P(X1)P(X2)P(X3|X2)P(X4|X1, X2)

Ad Feelders ( Universiteit Utrecht ) Data Mining 22 / 49

slide-23
SLIDE 23

Joint probability distribution of Bayesian Network

We can write the joint probability distribution more elegantly as P(X1, . . . , Xk) =

k

  • i=1

P(Xi | Xpa(i))

Ad Feelders ( Universiteit Utrecht ) Data Mining 23 / 49

slide-24
SLIDE 24

Independence Properties of DAGs: d-separation and Moral Graphs

Can we infer other/stronger independence statements from the directed graph like we did using separation in the undirected graphical models? Yes, the relevant concept is called d-separation. establishing d-separation directly (Pearl) establishing d-separation via the moral graph and “normal” separation We discuss the second approach.

Ad Feelders ( Universiteit Utrecht ) Data Mining 24 / 49

slide-25
SLIDE 25

Independence Properties of DAGs: Moral Graph

Given a DAG G = (K, E) we construct the moral graph G m by marrying parents, and deleting directions, that is,

1 For each i ∈ K, we connect all vertices in pa(i) with undirected edges. 2 We replace all directed edges in E with undirected ones.

DAG Moral Graph

Ad Feelders ( Universiteit Utrecht ) Data Mining 25 / 49

slide-26
SLIDE 26

Independence Properties of DAGs: Moral Graph

The directed independence graph G possesses the conditional independence properties of its associated moral graph G m. Why? We have the factorisation: P(X) =

k

  • i=1

P(Xi | Xpa(i)) =

k

  • i=1

gi(Xi, Xpa(i)) by setting gi(Xi, Xpa(i)) = P(Xi | Xpa(i)).

Ad Feelders ( Universiteit Utrecht ) Data Mining 26 / 49

slide-27
SLIDE 27

Independence Properties of DAGs: Moral Graph

We have the factorisation: P(X) =

k

  • i=1

gi(Xi, Xpa(i)) We thus have a factorisation of the joint probability distribution in terms of functions gi(Xai) where ai = {i} ∪ pa(i). By application of the factorisation criterion the sets ai become cliques in the undirected independence graph. These cliques are formed by moralization.

Ad Feelders ( Universiteit Utrecht ) Data Mining 27 / 49

slide-28
SLIDE 28

Moralisation: Example

X1 X2 X4 X3 X5

Ad Feelders ( Universiteit Utrecht ) Data Mining 28 / 49

slide-29
SLIDE 29

Moralisation: Example

X1 X2 X4 X3 X5

{i} ∪ pa(i) becomes a complete subgraph in the moral graph (by marrying all unmarried parents).

Ad Feelders ( Universiteit Utrecht ) Data Mining 29 / 49

slide-30
SLIDE 30

Moralisation Continued

Warning: the complete moral graph can obscure independencies! To verify i ⊥ ⊥ j | S construct the moral graph of the induced subgraph on: A = an+({i, j} ∪ S), that is, A contains i, j, S and all their ancestors. Let G = (K, E) and A ⊆ K. The induced subgraph GA contains nodes A and edges E ′, where i → j ∈ E ′ ⇔ i → j ∈ E and i ∈ A and j ∈ A.

Ad Feelders ( Universiteit Utrecht ) Data Mining 30 / 49

slide-31
SLIDE 31

Moralisation Continued

Since for ℓ ∈ A, pa(ℓ) ∈ A, we know that the joint distribution of XA is given by P(XA) =

  • ℓ∈A

P(Xℓ | Xpa(ℓ)) which corresponds to the subgraph GA of G.

1 This is a product of factors P(Xℓ|Xpa(ℓ)), involving the variables

X{ℓ}∪pa(ℓ) only.

2 So it factorizes according to G m

A , and thus the independence

properties for undirected graphs apply.

3 Hence, if S separates i from j in G m

A , then i ⊥

⊥ j | S.

Ad Feelders ( Universiteit Utrecht ) Data Mining 31 / 49

slide-32
SLIDE 32

Full moral graph may obscure independencies: example

G R A

P(G, R, A) = P(G)P(R)P(A | G, R) Does G ⊥ ⊥ R hold? Summing out A we obtain: P(G, R) =

  • a

P(G, R, A = a) (sum rule) =

  • a

P(G)P(R)P(A = a | G, R) (BN factorisation) = P(G)P(R)

  • a

P(A = a | G, R) (rule of summation) = P(G)P(R) (

a P(A = a | G, R) = 1) Ad Feelders ( Universiteit Utrecht ) Data Mining 32 / 49

slide-33
SLIDE 33

Poll

X1 X2 X4 X3 X5

1 Are X3 and X4 independent? 2 Are X1 and X3 independent? 3 Are X3 and X4 independent given X5? 4 Are X1 and X3 independent given X5? Ad Feelders ( Universiteit Utrecht ) Data Mining 33 / 49

slide-34
SLIDE 34

Equivalence

When no marrying of parents is required (there are no “immoralities” or “v-structures”), then the independence properties of the directed graph are identical to those of its undirected version. These three graphs express the same independence properties:

A B C A B C A B C

Ad Feelders ( Universiteit Utrecht ) Data Mining 34 / 49

slide-35
SLIDE 35

Learning Bayesian Networks

1 Parameter learning: structure known/given; we only need to estimate

the conditional probabilities from the data.

2 Structure learning: structure unknown; we need to learn the networks

structure as well as the corresponding conditional probabilities from the data.

Ad Feelders ( Universiteit Utrecht ) Data Mining 35 / 49

slide-36
SLIDE 36

Maximum Likelihood Estimation

Find value of unknown parameter(s) that maximize the probability of the

  • bserved data.

n independent observations on binary variable X ∈ {1, 2}. We observe n(1) outcomes X = 1 and n(2) = n − n(1) outcomes X = 2. What is the maximum likelihood estimate of p(1)? The likelihood function (probability of the data) is given by: L = p(1)n(1)(1 − p(1))n−n(1) Taking the log we get L = n(1) log p(1) + (n − n(1)) log(1 − p(1))

Ad Feelders ( Universiteit Utrecht ) Data Mining 36 / 49

slide-37
SLIDE 37

Maximum Likelihood Estimation

Take derivative with respect to p(1), equate to zero, and solve for p(1). dL dp(1) = n(1) p(1) − n − n(1) 1 − p(1) = 0, since d log x

dx

= 1

x (where log is the natural logarithm).

Solving for p(1), we get p(1) = n(1) n . This is just the fraction of one’s in the sample!

Ad Feelders ( Universiteit Utrecht ) Data Mining 37 / 49

slide-38
SLIDE 38

ML Estimation of Multinomial Distribution

Let X ∈ {1, 2, . . . , J}. Estimate the probabilities p(1), p(2), . . . , p(J) of getting outcomes 1, 2, . . . , J. If in n trials, we observe n(1) outcomes of 1, n(2) of 2, . . ., n(J) of J, then the obvious guess is to estimate p(j) = n(j) n , j = 1, 2, . . . , J. This is indeed the maximum likelihood estimate.

Ad Feelders ( Universiteit Utrecht ) Data Mining 38 / 49

slide-39
SLIDE 39

BN-Factorisation

For a given BN-DAG, the joint distribution factorises according to P(X) =

k

  • i=1

p(Xi | Xpa(i)) So to specify the distribution we have to estimate the probabilities p(Xi | Xpa(i)) i = 1, 2, . . . , k for the conditional distribution of each variable given its parents.

Ad Feelders ( Universiteit Utrecht ) Data Mining 39 / 49

slide-40
SLIDE 40

ML Estimation of BN

The joint probability for n independent observations is P(X (1), . . . , X (n)) =

n

  • j=1

P(X (j)) =

n

  • j=1

k

  • i=1

p(X (j)

i

| X (j)

pa(i)),

where X (j) denotes the j-th row in the data table. The likelihood function is therefore given by L =

k

  • i=1
  • xi,xpa(i)

p(xi | xpa(i))n(xi,xpa(i)) where n(xi, xpa(i)) is a count of the number of records with Xi = xi, and Xpa(i) = xpa(i).

Ad Feelders ( Universiteit Utrecht ) Data Mining 40 / 49

slide-41
SLIDE 41

ML Estimation of BN

Taking the log of the likelihood function, we get L =

k

  • i=1
  • xi,xpa(i)

n(xi, xpa(i)) log p(xi | xpa(i)) Maximize the log-likelihood function with respect to the unknown parameters p(xi | xpa(i)). This decomposes into a collection of independent multinomial estimation problems. Separate estimation problem for each Xi and configuration of Xpa(i).

Ad Feelders ( Universiteit Utrecht ) Data Mining 41 / 49

slide-42
SLIDE 42

Example BN and Factorisation

1 2 3 4

P(X1, X2, X3, X4) = p1(X1)p2(X2)p3|12(X3|X1, X2)p4|3(X4|X3)

Ad Feelders ( Universiteit Utrecht ) Data Mining 42 / 49

slide-43
SLIDE 43

Example BN: Parameters

P(X1, X2, X3, X4) = p1(X1)p2(X2)p3|12(X3|X1, X2)p4|3(X4|X3) Now we have to estimate the following parameters (X4 ternary, rest binary): p1(1) p1(2) = 1 − p1(1) p2(1) p2(2) = 1 − p2(1) p3|1,2(1|1, 1) p3|1,2(2|1, 1) = 1 − p3|1,2(1|1, 1) p3|1,2(1|1, 2) p3|1,2(2|1, 2) = 1 − p3|1,2(1|1, 2) p3|1,2(1|2, 1) p3|1,2(2|2, 1) = 1 − p3|1,2(1|2, 1) p3|1,2(1|2, 2) p3|1,2(2|2, 2) = 1 − p3|1,2(1|2, 2) p4|3(1|1) p4|3(2|1) p4|3(3|1) = 1 − p4|3(1|1) − p4|3(2|1) p4|3(1|2) p4|3(2|2) p4|3(3|2) = 1 − p4|3(1|2) − p4|3(2|2)

Ad Feelders ( Universiteit Utrecht ) Data Mining 43 / 49

slide-44
SLIDE 44

Example Data Set

  • bs

X1 X2 X3 X4 1 1 1 1 1 2 1 1 1 1 3 1 1 2 1 4 1 2 2 1 5 1 2 2 2 6 2 1 1 2 7 2 1 2 3 8 2 1 2 3 9 2 2 2 3 10 2 2 1 3

Ad Feelders ( Universiteit Utrecht ) Data Mining 44 / 49

slide-45
SLIDE 45

Maximum Likelihood Estimation

  • bs

X1 X2 X3 X4 1 1 1 1 1 2 1 1 1 1 3 1 1 2 1 4 1 2 2 1 5 1 2 2 2 6 2 1 1 2 7 2 1 2 3 8 2 1 2 3 9 2 2 2 3 10 2 2 1 3 ˆ p1(1) = n(x1 = 1) n = 5 10 = 1 2

Ad Feelders ( Universiteit Utrecht ) Data Mining 45 / 49

slide-46
SLIDE 46

Maximum Likelihood Estimation

  • bs

X1 X2 X3 X4 1 1 1 1 1 2 1 1 1 1 3 1 1 2 1 4 1 2 2 1 5 1 2 2 2 6 2 1 1 2 7 2 1 2 3 8 2 1 2 3 9 2 2 2 3 10 2 2 1 3 ˆ p2(1) = n(x2 = 1) n = 6 10

Ad Feelders ( Universiteit Utrecht ) Data Mining 46 / 49

slide-47
SLIDE 47

Maximum Likelihood Estimation

  • bs

X1 X2 X3 X4 1 1 1 1 1 2 1 1 1 1 3 1 1 2 1 4 1 2 2 1 5 1 2 2 2 6 2 1 1 2 7 2 1 2 3 8 2 1 2 3 9 2 2 2 3 10 2 2 1 3 ˆ p3|1,2(1|1, 1) = n(x1 = 1, x2 = 1, x3 = 1) n(x1 = 1, x2 = 1) = 2 3

Ad Feelders ( Universiteit Utrecht ) Data Mining 47 / 49

slide-48
SLIDE 48

Maximum Likelihood Estimation

  • bs

X1 X2 X3 X4 1 1 1 1 1 2 1 1 1 1 3 1 1 2 1 4 1 2 2 1 5 1 2 2 2 6 2 1 1 2 7 2 1 2 3 8 2 1 2 3 9 2 2 2 3 10 2 2 1 3 ˆ p3|1,2(1|1, 1) = n(x1 = 1, x2 = 1, x3 = 1) n(x1 = 1, x2 = 1) = 2 3

Ad Feelders ( Universiteit Utrecht ) Data Mining 48 / 49

slide-49
SLIDE 49

ML Estimation of BN

The maximum likelihood estimate of p(xi | xpa(i)) is given by: ˆ p(xi | xpa(i)) = n(xi, xpa(i)) n(xpa(i)) , where n(xi, xpa(i)) is the number of records in the data with Xi = xi and Xpa(i) = xpa(i), and n(xpa(i)) is the number of records in the data with Xpa(i) = xpa(i).

Ad Feelders ( Universiteit Utrecht ) Data Mining 49 / 49