Docsity

Decision Tree Classifiers - Introduction to Artificial Intelligence - Lecture Slides, Slides of Artificial Intelligence

Partial preview of the text

Download Decision Tree Classifiers - Introduction to Artificial Intelligence - Lecture Slides and more Slides Artificial Intelligence in PDF only on Docsity!

CSE 151 Machine Learning

Decision Tree Classifiers

X

1

X

2

Yes

No

Is X

2

Is X

1

Is X < 6?

1

Is X

2

No Yes

Yes

No No

Yes

Decision Tree Classifiers

Yes

No

Is X

2

< 3?

Is X

1

Is X < 6?

1

< 3?

Is X

2

< 7?

No Yes

Yes

No No

Yes

Each node is based on a feature

At each node, there is a decision

based on the value of the feature

Each leaf is a class (same class

may appear on multiple leaves)

An Example: Data

Iris data set

Features Petal Length(PL),

Petal Width (PW)

Petal Length(PL)

Petal Width(PW)

An Example: Data

Iris data set

Features Petal Length(PL),

Petal Width (PW)

Is PW < 0.75?

Yes

No

Is PL < 4.45?

Yes

No

Petal Length(PL)

Petal Width(PW)

An Example: Data

Iris data set

Features Petal Length(PL),

Petal Width (PW)

Is PW < 0.75?

Yes

No

Is PL < 4.45?

Yes

No

Is PW < 1.75?

Yes

No

Petal Length(PL)

Petal Width(PW)

In-Class Problem

Draw a decision tree for the following training data set.

In-Class Problem

Is X

1

Yes

No

Is X

2

Yes

No

Draw a decision tree for the following training data set.

Choosing a Feature (ID3 decision

trees)

Choose a feature, and a threshold that reduces uncertainty the most

How do we measure uncertainty?

Measure of Uncertainty: Entropy

Let X be a random variable(r.v) that takes values v

1

,..,v

k

with

probabilities p

1

,...,p

k

. Then, entropy of X, denoted by H(X), is defined as:

Example:

  1. X is a 0/1 random variable, P(X=1) = 0. What is H(X)?
  2. X is a 0/1 random variable, P(X=1) = 0.5. What is H(X)?
  3. X is a r.v which takes values 1,..,k with probabilities 1/k each.

What is H(X)?

H(X) = โˆ’

k

i=

p

i

log p

i

Conditional Entropy

Let X and Z be two random variables. The conditional entropy of X

given Z is defined as:

Essentially, what is the average entropy of X, given that we know Z

H(X|Z) =

z

Pr(Z = z)H(X|Z = z)

In-Class Problems:

  1. Suppose X = Z (so Z is a perfect predictor for X). What is H(X|Z)?
  2. Suppose X and Z are independent. What is H(X|Z)?

Conditional Entropy

Let X and Z be two random variables. The conditional entropy of X

given Z is defined as:

Essentially, what is the average entropy of X, given that we know Z

H(X|Z) =

z

Pr(Z = z)H(X|Z = z)

Information Gain(Z) = H(X) - H(X|Z)

Computing the Information Gain

Root: (5 R, 2 B)

H(X) = -(5/7) log(5/7) - (2/7) log(2/7)

X

1

X

2

a

Node a:

H(X|Z) = P(Z=0)H(X|Z=0) + P(Z=1)H(X|Z=1) = 0.

Node a

Z = Yes Z = No

(2 R, 0 B) (3 R, 2 B)

H(X|Z=0) = -(2/2) log(2/2) - (0/2) log (0/2)

H(X|Z=1) = -(3/5) log(3/5) - (2/5) log (2/5)

P(Z=0) = (2+0)/(5+2) = 2/

P(Z=1) = (3+2)/(5+2) = 5/

Choosing a Feature: Example

Root: (5 R, 2 B)

H(X) = 0.

X

1

X

2

a

b

c d

a: (2 R, 0 B), (3 R, 2 B)

H(X|Z) = 0.

b: (4 R, 0 B), (1 R, 2 B)

H(X|Z) = 0.

c: (5 R, 1 B), (0 R, 1 B)

H(X|Z) = 0.

d: (2 R, 2 B), (3 R, 0 B)

H(X|Z) = 0.

Recall, Information Gain(Z) = H(X) - H(X|Z)

Pick solution b