71
Class 7 Binary Classification & Decision Tree Learning Legal Analytics Professor Daniel Martin Katz Professor Michael J Bommarito II legalanalyticscourse.com

Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Embed Size (px)

Citation preview

Page 1: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Class 7Binary Classification & Decision Tree Learning

Legal Analytics

Professor Daniel Martin KatzProfessor Michael J Bommarito II

legalanalyticscourse.com

Page 2: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

< Binary Classification >

access more at legalanalyticscourse.com

Page 3: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

http://scikit-learn.org/stable/tutorial/machine_learning_map/index.htmlaccess more at legalanalyticscourse.com

Page 4: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Classification to Predict Quantity

Classification to Predict CategoryRegression Methods

Trees, Forests, Knn, etc.

access more at legalanalyticscourse.com

Page 5: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Adapted from Slides ByVictor Lavrenko and Nigel Goddard

@ University of EdinburghTake A Look These 12

access more at legalanalyticscourse.com

Page 6: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

72FemaleHuman

3FemaleHorse

36Male

Human

21Male

Human

67Male

Human

29FemaleHuman

54Male

Human

44Male

Human

50Male

Human

42FemaleHuman

6MaleDog

7FemaleHuman

Page 7: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Task = Determine Whether the Agents Will Obtain Employment?

Yes

Nof( )

Job?

Binary Classification (Supervised Learning)

access more at legalanalyticscourse.com

Page 8: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Classification (Supervised Learning)Yes

Nof( )

Job?

access more at legalanalyticscourse.com

Page 9: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Classification (Supervised Learning)

decision boundary

Yes

Nof( )

Job?

decision boundary

access more at legalanalyticscourse.com

Page 10: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Multi Class Classification

access more at legalanalyticscourse.com

Page 12: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Task = Determine Whether the Agents Will Obtain a Loan?

YesPerhapsf( )

Loan?

Multi Class Classification (Supervised Learning)

No

access more at legalanalyticscourse.com

Page 13: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

f( )

Multi Class Classification (Supervised Learning)

Loan?

YesPerhapsNo

access more at legalanalyticscourse.com

Page 14: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

f( )

Loan?

Yes

Multi Class Classification (Supervised Learning)

No

Maybe

YesPerhapsNo

access more at legalanalyticscourse.com

Page 15: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Multiclass = Hyperplaneaccess more at legalanalyticscourse.com

Page 16: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Task = Determine the Age of the Respective Agents

f( )

Age?

Regression (Supervised Learning)

#

access more at legalanalyticscourse.com

Page 17: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Generative vs.

Discriminant Models

access more at legalanalyticscourse.com

Page 18: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

access more at legalanalyticscourse.com

Page 19: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Follow the video and take your

own notes

Page 20: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Intro to Decision Tree LearningClassification And Regression Tree (CART)

access more at legalanalyticscourse.com

Page 21: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Decision Trees in Decision Theory

Decision Trees in Machine Learning≠

access more at legalanalyticscourse.com

Page 22: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito
Page 23: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito
Page 24: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Uses a set of binary rules applied to calculate a target value

Used for classification (categorical variables) or regression (continuous variables)

Different algorithms are used to determine the“best” split at a node

Introduction to Decision Trees

access more at legalanalyticscourse.com

Page 25: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

“CART Approach” to Decision Trees

Classification And Regression Tree (CART)

access more at legalanalyticscourse.com

Page 26: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

https://www.youtube.com/watch?v=WOOTNBxbi8caccess more at legalanalyticscourse.com

Page 27: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

http://www.r-bloggers.com/a-brief-tour-of-the-trees-and-forests/access more at legalanalyticscourse.com

Page 29: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

https://www.youtube.com/watch?v=_RxqyvRK0Rw&list=PLD0F06AA0D2E8FFBAaccess more at legalanalyticscourse.com

Page 30: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Given Some Data:(X1, Y1), ... , (Xn, Yn)

Now We Have a New Set of X’sWe Want to Predict the Y

access more at legalanalyticscourse.com

Page 31: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Form a Binary Tree thatMinimizes the Error in each leaf of the tree

CART (Classification & Regression Trees)

access more at legalanalyticscourse.com

Page 32: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Observe the Correspondence Between the Data and Trees

access more at legalanalyticscourse.com

Page 33: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0

Adapted from Example By Mathematical Monk

Page 34: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0

Adapted from Example By Mathematical Monk

We want to build an approach which can lead to the proper classification (labeling) of new data points ( ) that are dropped into this space

Page 35: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0

Adapted from Example By Mathematical Monk

Page 36: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0

Adapted from Example By Mathematical Monk

L e t s B e g i n t o Partition the Space

Page 37: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0

1 2

1

2

Adapted from Example By Mathematical Monk

L e t s B e g i n t o Partition the Space

split 1

(a)

Page 38: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0

1 2

1

2

Adapted from Example By Mathematical Monk

This Split Will Be Memorialized in the Tree

split 1

(a)

Page 39: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0

1 2

1

2

Adapted from Example By Mathematical Monk

We Ask the Question isXi1 > 1 ? - with a binary (yes or no) response

split 1

(a)

Xi1 > 1 ?

YesNo

Page 40: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0

1 2

1

2

Adapted from Example By Mathematical Monk

If No - then we are in zone (a) ... we tally the number of zeros and ones

Using Majority Rule do we assign a classification to this rule this leaf

split 1

(a)

Xi1 > 1 ?

YesNo

(0,5)Classify as 1

zone (a)

Page 41: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0

1 2

1

2

Adapted from Example By Mathematical Monk

Here we Classify as a 1 because (0,5) which is 0 zero’s and 5 one’s

split 1

(a)

Xi1 > 1 ?

YesNo

(0,5)Classify as 1

zone (a)

Page 42: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0

1 2

1

2

Adapted from Example By Mathematical Monk

Using a Similar Approach Lets Begin to Fill in the Rest of the Tree

split 1

(a)

Xi1 > 1 ?

YesNo

(0,5)Classify as 1

zone (a)

Page 43: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0

1 2

1

2

Adapted from Example By Mathematical Monk

split 1

(a)

Xi1 > 1 ?

YesNo

(0,5)Classify as 1

zone (a) Xi2 > 1.45 ?

No Yes

split 2

Page 44: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0split 1

split 2

split 3

1 2 2.2

1

2 Xi1 > 1 ?

(0,5) Xi2 > 1.45 ?

(4,1)(2,3)

Classify as 1

Classify as 1 Classify as 0

(a)

zone (a)

1.45YesNo

Adapted from Example By Mathematical Monk

No

(b)

(c)

zone (b) zone (c)

YesNo

Yes

Xi1 > 2 ?

Page 45: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0split 1

split 2

split 3

split 4

1 2 2.2

1

2 Xi1 > 1 ?

(0,5) Xi2 > 1.45 ?

Xi1 > 2.2 ?

(1,4)(5,0)(4,1)(2,3)

Classify as 1

Classify as 1 Classify as 0

(a)

zone (a)

1.45YesNo

Adapted from Example By Mathematical Monk

No

(b)

(c)

(d)

(e)

zone (b) zone (c)

YesNo YesNo

Yes

zone (d)Classify as 0 Classify as 1

zone (e)

Xi1 > 2 ?

Page 46: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Okay Lets Add Back the ( ) which are new items

to be classified

Page 47: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

For simplicity sake there is one in each zone

Page 48: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

We Will Use the Tree Becausethe Tree Is Our Prediction Machine

Page 49: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0split 1

split 2

split 3

split 4

1 2 2.2

1

2 Xi1 > 1 ?

(0,5) Xi2 > 1.45 ?

Xi1 > 2.2 ?

(1,4)(5,0)(4,1)(2,3)

Classify as 1

Classify as 1 Classify as 0

(a)

zone (a)

1.45YesNo

Adapted from Example By Mathematical Monk

No

(b)

(c)

(d)

(e)

zone (b) zone (c)

YesNo YesNo

Yes

zone (d)Classify as 0 Classify as 1

zone (e)

Xi1 > 2 ?

Page 50: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0split 1

split 2

split 3

split 4

1 2 2.2

1

2 Xi1 > 1 ?

(0,5) Xi2 > 1.45 ?

Xi1 > 2.2 ?

(1,4)(5,0)(4,1)(2,3)

Classify as 1

Classify as 1 Classify as 0

(a)

zone (a)

1.45YesNo

Adapted from Example By Mathematical Monk

No

(b)

(c)

(d)

(e)

zone (b) zone (c)

Yes No YesNo

Yes

zone (d)Classify as 0 Classify as 1

zone (e)

1

1

1

0 1

0

Xi1 > 2 ?

Page 51: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

10

1

11

0

0

0

0

0

1

1 11

00

1

1

1

1

0010

Xi1

Xi2

0

1 2

1

2

3

00

00

1

1

1

1

11 10

00

0

11 11

1 1

00

1

1 1

0

A B C

D

E

F

G

How about this one?

Page 52: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito
Page 53: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

In this simple example, we eyeballed the 2D space, partitioned

it and stopped after 4 Splits

access more at legalanalyticscourse.com

Page 54: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Most Real Problems are Not So Simple ...

access more at legalanalyticscourse.com

Page 55: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Real problems are n-dimensional (not 2D)

(1)

access more at legalanalyticscourse.com

Page 56: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

For real problems, you need to select criteria

(or a criterion) for deciding where to

partition (split) the data

(2)

access more at legalanalyticscourse.com

Page 57: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

For real problems you must develop a stopping condition

or pursue recursive partitioning of the space

(3)

access more at legalanalyticscourse.com

Page 58: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Solutions to these 3 Problems are among the core questions in

algorithm selection / development

access more at legalanalyticscourse.com

Page 59: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

From an Algorithmic Perspective - The Task is to Develop a

Method to Partition the Trees

access more at legalanalyticscourse.com

Page 60: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Must Do So Without Knowing the Specific Contours of the Data / Problem in Question

access more at legalanalyticscourse.com

Page 61: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito
Page 62: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

So How Do We Traverse Through

The Data?

access more at legalanalyticscourse.com

Page 63: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Optimal Partitioning of Trees is NP-Complete

access more at legalanalyticscourse.com

Page 64: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

“Although any given solution to an NP-complete problem can be verified quickly (in polynomial time), there is no known efficient way to locate a solution in the first place; indeed, the most notable characteristic of NP-complete problems is that no fast solution to them is known. That is, the time required to solve the problem using any currently known algorithm increases very quickly as the size of the problem grows”

Page 65: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

key implication is that one cannot in advance determine

the “optimal tree”

access more at legalanalyticscourse.com

Page 66: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Breiman, et al (1984) uses a Greedy Optimization Method

access more at legalanalyticscourse.com

Page 67: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Greedy Optimization Method is used to calculate the MLE

(maximum-likelihood estimation)

access more at legalanalyticscourse.com

Page 68: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Greedy is a Heuristic “makes the locally optimal choice at each stage with the hope of finding a global optimum. In many problems, a greedy strategy does not in general produce an optimal solution, but nonetheless a greedy heuristic may yield locally optimal solutions that approximate a global optimal solution in a reasonable time.”

access more at legalanalyticscourse.com

Page 69: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito
Page 70: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

More on Trees (and Forests)Next Time ...

access more at legalanalyticscourse.com

Page 71: Legal Analytics Course - Class 7 - Binary Classification with Decision Tree Learning - Professor Daniel Martin Katz + Professor Michael J Bommarito

Legal AnalyticsClass 7 - Binary Classification with Decision Tree Learning

daniel martin katz

blog | ComputationalLegalStudies

corp | LexPredict

michael j bommarito

twitter | @computational

blog | ComputationalLegalStudies

corp | LexPredict

twitter | @mjbommar

more content available at legalanalyticscourse.com

site | danielmartinkatz.com site | bommaritollc.com