It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A...

24

Transcript of It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A...

Page 1: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

It can not be emphasized enough that no claim whatsoever is

being made in this paper that all algorithms are equivalent in

practice, in the real world. In particular, no claim is being made

that one should not use cross-validation in the real world.

|Wolpert, 1994

Cross-Validation and Bootstrap

for Accuracy Estimation and Model Selection

Ron Kohavi

Stanford University

IJCAI-95

([email protected])

1

Page 2: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Motivation & Summary of Results

You have ten induction algorithms. Which one is the best for a

given dataset?

Answer: run them all and pick the one with the highest estimated

accuracy.

1. Which accuracy estimation?

Resubstitution? Holdout? Cross-validation? Bootstrap?

2. How sure would you be of your choice?

3. If you had spare CPU cycles, would you alway choose leave-

one-out?

For accuracy estimation: strati�ed 10 to 20-fold CV.

For model selection: multiple runs of 3-5 CV.

([email protected])

2

Page 3: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Talk Outline

➀☞ Accuracy estimation: the problem.

➁ Accuracy estimation methods:

F

Holdout & random subsampling.

F

Cross-validation.

F

Bootstrap.

➂ Experiments, recent experiments.

➃ Summary.

([email protected])

3

Page 4: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Basic De�nitions

1. Let D be a dataset of n labelled instances.

2. Assume D is an i.i.d. sample from some underlying distribu-

tion on the set of labelled instances.

3. Let I be an induction algorithm that produces a classi�er

from data D.

([email protected])

4

Page 5: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

The Problem

Estimate the accuracy of the classi�er induced from the dataset.

The accuracy of a classi�er is the probability of correctly clas-

sifying a randomly selected instance from the distribution.

All resampling methods (holdout, cross-validation, bootstrap)

will use a uniform distribution on the given dataset as a distri-

bution from which they sample.

Real world

Distribution F

Dataset

Distribution F’Sample 2

Sample k

Sample 1

([email protected])

5

Page 6: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Holdout

Holdout partition the data into two mutually exclusive subsets

called a training set and a test set. The training set is given to

the inducer, and the induced classi�er is tested on the test set.

Training Set1 2 3

2/3

1/3

InducerEval

Classifier

Pessimistic estimator because only a portion of the data is given

to the inducer for training.

([email protected])

6

Page 7: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Con�dence Bounds

The classi�cation of each test instance can be viewed as a

Bernoulli trial: correct or incorrect prediction.

Let S be the number of correct classi�cations on the test set of

size h, then S is distributed binomially and S=h is approximately

normal with mean acc and variance of acc � (1� acc)=h.

Pr

8><>:

�z <

acc

h

� acc

q

acc(1� acc)=h

< z

9>=>;

� (1)

([email protected])

7

Page 8: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Random Subsampling

Repeating the holdout many times is called random subsampling.

Common mistake:

One cannot compute the standard deviation of the sam-

ples' mean accuracy in random subsampling because the

test instances are not independent.

The t-tests you commonly see with signi�cance levels are

usually wrong.

Example: random concept (50% for each class). One induc-

tion algorithm predicts 0, the other 1. Given a sample of 100

instances, chances are it won't be 50/50, but something like

53/47. Leaving 1/3 out gives s.d.=8.7%.

([email protected])

8

Page 9: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Audience comments?

Pedro Domingos et al., please keep the comments to the end.

Accuracy as de�ned here is the prediction accuracy on instances

sampled from the parent population, not from the small dataset

we have at hand.

t-tests with random subsampling tests the hypothesis that one

algorithm is better than another, assuming the distribution is

uniform and each instance in the dataset has 1=n probability.

This is not an interesting hypothesis, except that we know how

to compute it.

([email protected])

9

Page 10: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Cross Validation

In k-fold cross-validation, the dataset D is randomly split into k

mutually exclusive subsets (the folds) D

1

;D

2

; : : : ;D

k

of approxi-

mately equal size.

The inducer is trained and tested k times; each time t 2

f1;2; : : : ; kg it is trained on D n D

t

and tested on D

t

.

1

2

3Inducer

Inducer

Inducer

Training Set1 2 3

1 2

1 3

3 2

c

c

c

Eval

Eval

Eval

Avg

Train: Test:

([email protected])

10

Page 11: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Standard Deviation

Two ways to look at cross-validation:

1. A method that works for stable inducers, i.e., inducers that

do not change their predictions much when given similar

datasets (see paper).

2. A method of computing the expected accuracy for a dataset

of size n� k=n, where k is the number of folds.

Since each instance is used only once as a test instance, the

standard deviation can be estimated as acc

cv

� (1 � acc

cv

)=n,

where n is the number of instances in the dataset.

([email protected])

11

Page 12: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Failure of cross-validation/leave-one-out

Leave-one-out is n-fold cross-validation.

Fisher's iris dataset contains 50 instances of each class (three

classes), leading one to expect that a majority inducer should

have accuracy about 33%.

When an instance is deleted from the dataset, its label is a

minority in the training set; thus the majority inducer predicts

one of the other two classes and always errs in classifying the

test instance.

The leave-one-out estimated accuracy for a majority in-

ducer on the iris dataset is therefore 0%�0%

([email protected])

12

Page 13: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

.632 Bootstrap

A bootstrap sample is created by sampling n instances uni-

formly from the data (with replacement).

Given a number b, the number of bootstrap samples, let �0

i

be

the accuracy estimate for bootstrap sample i on the instances

not included in the sample. The .632 bootstrap estimate is

de�ned as

acc

boot

=

1

b

b

X

i=1

(0:632 � �0

i

+ :368 � acc

s

)

where acc

s

is the resubstitution accuracy estimate on the full

dataset.

([email protected])

13

Page 14: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Bootstrap failure

The .632 bootstrap fails to give the expected result when the

classi�er can perfectly �t the data (e.g., an unpruned decision

tree or a one nearest neighbor classi�er) and the dataset is com-

pletely random, say with two classes.

The apparent accuracy is 100%, and the �0 accuracy is about

50%. Plugging these into the bootstrap formula, one gets an

estimated accuracy of about 68.4%, far from the real accuracy

of 50%.

([email protected])

14

Page 15: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Experimental design: Q & A

1. Which induction algorithm to use? C4.5 and Naive Bayes.

Reason: FAST inducers.

2. Which datasets to use? Seven datasets were chosen.

Reasons:

(a) Wide variety of domains.

(b) At least 500 instances.

(c) Learning curve that did not atten too early.

([email protected])

15

Page 16: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Learning Curves

50 100 150 200 250TS size

Breast cancer

8284868890929496

% Accuracy

C4.5NB

500 1000 2000 3000TS size

Chess endgames

82.585

87.590

92.595

97.5100

% Accuracy

C4.5

NB

500 1500 2500TS size

Hypothyroid

97

97.5

98

98.5

99

% Accuracy

C4.5

NB

2000 4000 6000 8000TS size

Mushroom

94

95

96

97

98

99

100

% Accuracy

C4.5

NB

50 100 150 200TS size

Soybean (large)

20

30

40

50

60

70

80

% Accuracy

C4.5NB

100 200 300 400TS size

Vehicle

35

40

45

50

55

60

65

70

% Accuracy

C4.5

NB

Arrow indicate sampling points.

([email protected])

16

Page 17: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

The bias (CV)

The bias of a method that estimates a parameter � is de�ned as

the expected estimated value minus the value of �. An unbiased

estimation method is a method that has zero bias.

2 5 10 20 -5 -2 -1folds45

50

55

60

65

70

75% acc

Soybean

Vehicle

Rand

2 5 10 20 -5 -2 -1folds96

96.5

97

97.5

98

98.5

99

99.5

100% acc

ChessHypo

Mushroom

C4.5: The bias of cross-validation with varying folds. A negative k folds

stands for leave-k-out. Error bars are 95% con�dence intervals for the mean.

The gray regions indicate 95% con�dence intervals for the true accuracies.

([email protected])

17

Page 18: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Bootstrap Bias

Bootstrap is right on the mark for three out of six, but biased

for soybean and extremely biased for vehicle and rand.

1 2 5 10 20 50 100samples45

50

55

60

65

70

75

% acc

SoybeanVehicle

Rand

Estimated

Soybean

Vehicle

Rand

1 2 5 10 20 50 100samples96

96.5

97

97.5

98

98.5

99

99.5

100% acc

ChessHypo

Mushroom

C4.5: The bias of bootstrap.

([email protected])

18

Page 19: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

The Variance of CV

The variance is high at the ends: two fold and leave-f1,2g-out

2 5 10 20 -5 -2 -1folds

C4.5

0

1

2

3

4

5

6

7

std dev

MushroomChessHypo

Breast

VehicleSoybean

Rand

2 5 10 20 -5 -2folds

C4.5

0

1

2

3

4

5

6

7

std dev

MushroomChessHypo

Breast

VehicleSoybean

Rand

Regular (left), Strati�ed (right).

Strati�cation slightly reduces both bias and variance.

([email protected])

19

Page 20: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

The Variance of Bootstrap

1 2 5 10 20 50 100samples

C4.5

0

1

2

3

4

5

6

7

std dev

MushroomChess

Hypo

Breast

Vehicle

Soybean

Rand

1 2 5 10 20 50 100samples

Naive-Bayes

0

1

2

3

4

5

6

7

std dev

Mushroom

ChessHypo

Breast

Vehicle

Soybean

Rand

([email protected])

20

Page 21: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Multiple Times

To stabilize the cross-validation, we can execute CV multiple

times, shu�ing the instances each time.

2 5 10 20 -5 -2folds

C4.5: 5 x CV

0

1

2

3

4

5

6

7

std dev

MushroomChessHypo

BreastVehicleSoybean

Rand

2 5 10 20 -5 -2folds

Naive Bayes: 5 x CV

0

1

2

3

4

5

6

7

std dev

Mushroom

ChessHypo

Breast

VehicleSoybean

Rand

The graphs show the e�ect on C4.5 and NB when CV was run

�ve times. The variance for lower folds was due to the variance

because of smaller dataset size.

([email protected])

21

Page 22: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

Summary

1. Reviewed accuracy estimation: holdout, cross-validation,

strati�ed CV, bootstrap. All methods fail in some cases.

2. Bootstrap has low variance, but is extremely biased.

3. With cross-validation, you can determine the bias/variance

tradeo� that is appropriate, and run multiple times to reduce

variance.

4. Standard deviations can be computed for cross-validation,

but are incorrect for random subsampling (holdout).

Recommendation

For accuracy estimation: strati�ed 10 to 20-fold CV.

For model selection: multiple runs of 3-5 folds (dynamic).

([email protected])

22

Page 23: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

What is the \true" accuracy

To estimate the true accuracy at the sampling points, we sam-

pled 500 times and estimated the accuracy using the unseen

instances (holdout).

Dataset no. of sample-size no. of C4.5 Naive-Bayes

attr. / total size categories

Breast cancer 10 50/699 2 91.37�0.10 94.22�0.10

Chess 36 900/3196 2 98.19�0.03 86.80�0.07

Hypothyroid 25 400/3163 2 98.52�0.03 97.63�0.02

Mushroom 22 800/8124 2 99.36�0.02 94.54�0.03

Soybean large 35 100/683 19 70.49�0.22 79.76�0.14

Vehicle 18 100/846 4 60.11�0.16 46.80�0.16

Rand 20 100/3000 2 49.96�0.04 49.90�0.04

([email protected])

23

Page 24: It - Artificial Intelligencerobotics.stanford.edu › people › ronnyk › accEst-talk.pdf · 1. A metho d that rks o w r fo stable inducers, i.e., inducers do not change their redictions

How Many Times Should We Repeat?

1 2 3 5 10 20 50 100times

C4.5: 2-fold CV

0

1

2

3

4

5

6

7

std dev

MushroomChessHypo

Breast

VehicleSoybean

Rand

1 2 3 5 10 20 50 100times

Naive Bayes: 2-fold CV

0

1

2

3

4

5

6

7

std dev

Mushroom

ChessHypo

Breast

Vehicle

SoybeanRand

Multiple runs with two-fold CV. The more, the better.

([email protected])

24