<Predicting Baseball Player's Salaries Using Regression Trees>
predictors : Years(메이저리그에서 몇년있었는지) / Hits(전년도의 Hits수)
reponse : Salary
Tree 구조 : Nodes(Terminal Nodes, Internal Nodes) / Splitting Ruels / branches

Terminal Nodes 를 수식으로 표현하면 위와 같이 R1,R2,R3의 Region으로 표현할 수 있음
<Predicting Baseball Player's Salaries Using Regression Trees>

(따라서, 같은 terminal Nodes에 있는 data들의 예측값으 모두 동일)
goal : find boxes R1,R2,R3..Rj that minimize the RSS

모든 경우의 수의 Splitting case를 전부 살펴볼 수 없기 때문에 top-down approach를 이용한다.
HOW? 모든 Predictors와 그에 해당하는 모든 cutpoint를 고려한 뒤, lowest RSS를 가져다주도록 Splitting Rule을 결정
단. 전 단계에서 생성된 2개의 regions을 전부 split하는 것이 아닌, 두개 중 하나의 region만 Split한다.
Tree Pruning
적절한 tree structure는 어떻게 얻어내는가?
→ 그러나 이렇게 단순한 방법으로 tree structure를 결정하면, 중요한 split rule이 뒤에 나오게 될 경우 RSS가 매우 커지는 단점이 있음.
하지만 모든 subtree의 test error rate을 전부 계산할 수는 없음
→ selecting a samll set of subtrees for consideration : Cost Complexity pruning
: 모든 subtree를 계산하는 것이 아니라, 적절한 tuning parameter에 따라 결정된 subtree 후보 몇개만 살펴 보는 것
T : # of terminal tree (tree complexity)
a : tuning parameter
좌측 항 : RSS / 우측 항 : tree complexity에 대한 Penalty (a)
(a = 0이면, RSS를 최소로 하는 tree를 결정하면 되니까, T0를 선택하게 됨.
a 가 커질수록, Tree complexity에 대한 penalty는 커짐)

1 : 가장 큰 Tree를 만드는 것 (각 terminal node에 포함된 observations의 수가 some min number보다 작을 때)
2, 3 : pruning parameter값 결정
4 : final tree결정
예측값 : 해당 Terminal Node에서 가장 빈도수가 높은 class of training observations 로 예측
(Most Commly occurring class)
RSS 대신 Classification error rate을 이용
<Classification error rate>
Most commonly occurring class (해당 Terminal Node에서 예측할 Class)에 속하지 못한 class의 비율

(Pmk : m번째 구역의 k번째 class의 비율)
tree-growing에 sensitive하지 않기 때문에, 뒤에 두개의 방법을 더 선호함
<Gini index (Gini impurity)>

class가 덜 분류되어 덜 순수한 정도 반영
ex ) Class 가 2개 있는 경우 Pm1 = 1 , Pm2 =0 이어서 완벽히 분리된 경우 G는 0으로 계산된다.
Pm1 = 1/2 , Pm2 =1/2 이어서 반반 섞여 있는 경우, G는 0.5로 계산되어 값이 커지는 것을 알 수 있다.
→ Mth node가 pure(잘 분리되어 있을수록) small value를 가진다.
<Entropy>

Gini index 와 거의 유사한 값을 가진다
분류 트리를 생성할 때는 gini impurity 혹은 entropy가 분기를 나누는 데에는 더 적합하여 주로 사용된다. 반면, 트리를 pruning 하는 작업에서는 정확도를 높이기 위해 classification error rate가 더 선호된다.
한쪽 leaf이 보다 정확히 class를 분류하여 node purity를 증가시키는 경우 → test 에서의 정확한 분리를 위하여

linear model : features와 response의 관계가 linear일 때
tree model : non-linear and complex relationship btw features and response / 해석 및 시각화의 용이성이 필요할 때
Advantages
Disdvantages
: High Variance
→ 문제 해결 : aggregating many decision trees
ensemble : simple building block model을 combining
goal : Low varaince → averaging a set of observations reduce variance
여러개의 seperate training set을 이용해 얻어낸 값을 평균 내면 variance가 낮아짐
실제로는 train set을 여러개 얻기 어렵기 때문에

→ Bagging
tree에서 Bagging
B의 개수(single tree의 개수)는 overfitting 일으키지 않음
Out-of-Bag Error Estimaion
→ 이를 이용하여 Validation Test
전체 데이터 중 약 2/3정도가 한번의 Bootstarp에서 추출됨
B개의 single tree 중 i 번째 observation을 사용하지 않은 B/3개의 tree를 앙상블 하여 i번째 Observation에 대한 Validation Test 를 진행함
총 n개의 obervaion에 대해서 위와 같은 방법으로 prediction하면, overall OOB MSE / classification error를 얻을 수 있음
Variable Importance Measures
Bagging을 사용하면 model을 interpret하기 어려워지고, 어떤 variables가 tree building에 중요한 역할을 했는지 판별하기어려워짐
→ 이때, 각 tree에서 어떤 variables가 RSS 혹은 Gini Index를 줄이는데 일조했는지 record하고 가장 기여도가 높았던 순서대로 제시해줌으로써, Variable Importance 를 측정할 수 있게 해줌

Bagging을 이용한다고 해도, 중요한 변수들은 고정되어있어 각 tree의 구조는 유사할 것이다
→ highly correlated trees
→ highly correlated quantites 들을 평균내는 것은 reduction Variance에 큰 도움이 안 됨
→ uncorrelated trees들이 필요 :
그렇게 선택된 m개의 변수로 각 tree 구성 후, 평균을 내어 최종 예측 model이 구성됨
( m 의 개수는 일반적으로 p의 제곱근 : 그때 가장 성능 좋음)

Bagging과 유사하나, bootstrap sampling을 이용하지 않고 이전 tree 정보를 이용하여 sequentially grown 함.

→ repeat하여 Fitted function 을 improving
: each tree depends strongly on the trees that have already been grown
Tuning Parameters

Bagging
Random Forest
Boosting
: current model이 설명해내지 못한 signal(residual)을 이용해 tree를 fit하고 이를 이용하여 fitted function을 update 시키고, 설명되지 않은 residual에서 설명된 부분 또한 update시킴