Week 12
Week 12
Dr Carla Ewels
[email protected]
Oct 2021
Recap
1
2
1
1
X2
X2
0
0
−1
−1
−2
−2
−2 −1 0 1 2 −2 −1 0 1 2
X1 X1
2
2
1
1
X2
X2
0
0
−1
−1
−2
−2
−2 −1 0 1 2 −2 −1 0 1 2
X1 X1
Carla Ewels |
Example
3
1
Labour
.30 .47 .22
100%
yes Blair < 3.5 no 3
Labour
.16 .61 .22
65%
Hague >= 3.5
6
Labour
.37 .44 .19
22%
Europe >= 7.5
2 12 13 7
Conservative Conservative Labour Labour
.56 .21 .23 .54 .30 .16 .21 .56 .22 .06 .70 .24
35% 10% 12% 43%
X K
X
p̂mk p̂mk0 = p̂mk (1 − p̂mk )
k6=k0 k=1
Carla Ewels |
Advanced trees
5
Carla Ewels |
Bagging
6
Carla Ewels |
Bootstrapping
7
I Resampling method
I Draw random samples with replacement from training set
I Grow a tree
I Prediction
I Repeat for many times
I Prediction, regression tree
B
1 X ˆ∗b
fˆbag (x) = f (x)
B
b=1
Carla Ewels |
Step illustration
8
Carla Ewels |
Bagging Classification tree
9
Carla Ewels |
Other issues with bagging
10
I A bagged tree does not retain the tree structure, therefore hard
to interpret (black box)
I A bagged tree is not a tree
Carla Ewels |
Random Forest
11
Carla Ewels |
Random Forest
12
1. For b = 1, . . . , B
(a) Draw a bootstrapping sample, Z ∗ of size N from training data (with
replacement)
(b) Grow a random-forest tree Tb to the bootstrapped data by
recursively repeating the following step for each terminal node of
the tree, until the minimum node size nmin is reached
i Select m variables at random from the p variables
ii Pick the best variable/split-point among the m
iii Split the node
(c) Output of ensemble of trees {Tb }B
1
Carla Ewels |
Random Forest
13
I Let P be size of all predictors, the typical size of the subset (m)
√
I P for classification
I p/2 for regression
I When m = P , random forest is the same as bagging.
I Prediction
I Regression,
B
1 X
fˆrf
B
(x) = Tb (x)
B
b=1
I Classification,
Let Ĉb (x) be the prediction of the bth random-forest tree, then
B
Ĉrf (x) = majority vote{Ĉb (x)}B
1
Carla Ewels |
Bagging and Random Forest in R
14
Carla Ewels |
Example: Heart data
15
Carla Ewels |
Example: Heart
16
Thal:a
|
Thal:a
|
0.6
Training
Cross−Validation
Test
0.5
0.4
Error
0.3
Yes Yes
0.1
No No
No Yes
5 10 15
Tree Size
Carla Ewels |
Example: Heart
17
than Bagging
I No overfitting issue with
Error
0.20
Test: Bagging
Test: RandomForest
OOB: Bagging
0.10
OOB: RandomForest
Number of Trees
Carla Ewels |
Example: Random forest with different subset
sizes 18
Carla Ewels |
Example: Random forest with different subset
sizes 19
m=p
m=p/2
0.5
m= p
Test Classification Error
0.4
0.3
0.2
Number of Trees
Carla Ewels |
Boosted tree
20
Carla Ewels |
Example:AdaBoost
21
I AdaBoost
I classification problem with
K = 2, Y ∈ {−1, 1}
I Prediction
M
X
G(x) = sign αm Gm (x)
m=1
Carla Ewels |
Example:AdaBoost
22
Carla Ewels |
Example:AdaBoost
23
Carla Ewels |
Boosting algorithm for regression tree
24
Carla Ewels |
Extension of Boosted tree
25
Carla Ewels |
Tuning parameters
26
Carla Ewels |
Example
27
Carla Ewels |
Example
28
Carla Ewels |
Interpretation of trees
29
Carla Ewels |
Variable importance
30
Carla Ewels |
Random Forest
31
Carla Ewels |
Boosting
32
Carla Ewels |
Partial dependency plot
33
Carla Ewels |