Decision Tree

Decision Tree

  • ė°ģ“ķ„°ė„¼ ė¶„ģ„ķ•˜ģ—¬ ģ“ė“¤ ģ‚¬ģ“ģ— ģ”“ģž¬ķ•˜ėŠ” ķŒØķ„“ģ„ 예츔 ź°€ėŠ„ķ•œ ź·œģ¹™ė“¤ģ˜ ģ”°ķ•©ģœ¼ė”œ ė‚˜ķƒ€ėƒ„.

  • ė¶„ė„˜(Classification)와 ķšŒź·€(Regression) ė¬øģ œģ— 적용 ź°€ėŠ„.

  • ź³„ģ‚°ė³µģž”ģ„± ėŒ€ė¹„ ė†’ģ€ 예츔 ģ„±ėŠ„ģ„ ģ§€ė‹˜.

Example (Process of Decsion Tree)

  • Find the feature and criteria that best differentiate the data.

  • Q) How to findd the criteria that best differentiate the data?

    • -> Maximize the information gain. (Minimize the Impurity (Entropy))

Entropy, Impurity

  • ė¶ˆģˆœė„ (Impruty)

    • 핓당 범주 ģ•ˆģ— ģ„œė”œ 다넸 ė°ģ“ķ„°ź°€ ģ–¼ė§ˆė‚˜ ģ„žģ—¬ ģžˆėŠ”ź°€?

  • Entropy

    • ė¶ˆģˆœė„ė„¼ 수치적으딜 ė‚˜ķƒ€ė‚ø ģ²™ė„

Entropy=āˆ’āˆ‘i(pi)log⁔2(pi)Entropy = - \sum\nolimits_i {({p_i}){{\log }_2}({p_i})}

Entropy Example

Impurity Indicator

  • Entropy Entropy(A)=āˆ‘i=1dRi(āˆ’āˆ‘k=1mpklog⁔2(pk))Entropy(A) = \sum\limits_{i = 1}^d {{R_i}\left( { - \sum\limits_{k = 1}^m {{p_k}{{\log }_2}({p_k})} } \right)}

  • Gini-Index G.I(A)=āˆ‘i=1d(Ri(1āˆ’āˆ‘k=1mpik2))G.I(A) = \sum\limits_{i = 1}^d {\left( {{R_i}\left( {1 - \sum\limits_{k = 1}^m {{p_{ik}}^2} } \right)} \right)}

Rish of Overfitting

  • Decision trees tend to overfit on data with a large number of features. Getting the right ratio of samples to number of features is important, since a tree with few samples in high dimensional space is very likely to overfit.

  • We have to limit the maximum depth, the maximum number of nodes, minimum number of data for one node to split.

Pruning

  • Prevent overfitting using pruning.

Cost Function of Pruning

  • š¶š¶(š‘‡)=šøš‘Ÿš‘Ÿ(š‘‡)+š›¼Ć—šæ(š‘‡)

    • š¶š¶(š‘‡): ģ˜ģ‚¬ź²°ģ •ė‚˜ė¬“ģ˜ ė¹„ģš© ė³µģž”ė„ (=ģ˜¤ė„˜ź°€ ģ ģœ¼ė©“ģ„œ terminal node ģˆ˜ź°€ ģ ģ€ ė‹Øģˆœķ•œ ėŖØėøģ¼ģˆ˜ė” ģž‘ģ€ ź°’)

    • šøš‘…š‘…(š‘‡): ź²€ģ¦ ė°ģ“ķ„°ģ— ėŒ€ķ•œ ģ˜¤ė¶„ė„˜ģœØ

    • šæ(š‘‡): terminal nodeģ˜ 수 (구씰 ė³µģž”ė„)

    • š“š‘™š‘ā„Žš‘Ž: šøš‘…š‘…(š‘‡)와 šæ(š‘‡)넼 ź²°ķ•©ķ•˜ėŠ” ź°€ģ¤‘ģ¹˜ (ģ‚¬ģš©ģžģ— ģ˜ķ•“ 부여, 볓통 0.01~0.1ģ˜ ź°’ģ„ ģ‚¬ģš©)

Summary

  • ģ˜ģ‚¬ź²°ģ •ė‚˜ė¬“ėŠ” ķ•œė²ˆģ— ķ•˜ė‚˜ģ”©ģ˜ ģ„¤ėŖ…ė³€ģˆ˜ė„¼ ģ‚¬ģš©ķ•˜ģ—¬ 예츔 ź°€ėŠ„ķ•œ ź·œģ¹™ė“¤ģ˜ ģ§‘ķ•©ģ„ ģƒģ„±ķ•˜ėŠ” ģ•Œź³ ė¦¬ģ¦˜.

    • ķ•œė²ˆ ė¶„źø° ė•Œė§ˆė‹¤ ė³€ģˆ˜ ģ˜ģ—­ģ„ ė‘ź°œė”œ źµ¬ė¶„ķ•œ ė’¤ 각 ģ˜ģ—­ģ˜ ģˆœė„ź°€ ģ¦ź°€(ģ—”ķŠøė”œķ”¼ź°€ ź°ģ†Œ)ķ•˜ėŠ” ė°©ķ–„ģœ¼ė”œ ķ•™ģŠµģ„ 진행함.

    • ģž…ė „ ė³€ģˆ˜ ģ˜ģ—­ģ„ 두 개딜 źµ¬ė¶„ķ•˜ėŠ” **ģž¬ź·€ģ  ė¶„źø°(recursive partioning)**와 źµ¬ė¶„ėœ ģ˜ģ—­ģ„ ķ†µķ•©ķ•˜ėŠ” **ź°€ģ§€ģ¹˜źø°(pruning)**ģ˜ 두가지 ź³¼ģ •ģœ¼ė”œ ė‚˜ė‰Ø.

  • ģ˜ģ‚¬ź²°ģ •ė‚˜ė¬“ėŠ” ź³„ģ‚°ė³µģž”ģ„± ėŒ€ė¹„ ė†’ģ€ 예츔 ģ„±ėŠ„ģ„ ė‚“ėŠ” ģž„ģ ģ„ ģ§€ė‹˜.

  • ķ•˜ģ§€ė§Œ, 결정경계(decision boundary)ź°€ ė°ģ“ķ„° 축에 ģˆ˜ģ§ģ“ģ–“ģ„œ ķŠ¹ģ • ė°ģ“ķ„°ģ—ė§Œ ģž˜ ģž‘ė™ķ•˜ėŠ” ķ•œź³„ź°€ ģžˆģŒ.

    • ģ“ėŸ¬ķ•œ 문제넼 ź·¹ė³µķ•˜źø° ģœ„ķ•“ ėžœė¤ķ¬ė ˆģŠ¤ķŠøģ™€ ź°™ģ€ źø°ė²•ģ„ ģ‚¬ģš©.

    • ėžœė¤ķ¬ė ˆģŠ¤ķŠøėž€?

      • ź°™ģ€ ė°ģ“ķ„°ģ— ėŒ€ķ•“ ģ˜ģ‚¬ź²°ģ •ė‚˜ė¬“ė„¼ ģ—¬ėŸ¬ 개 ė§Œė“¤ģ–“ģ„œ ź·ø 결과넼 ģ”°ķ•©ķ•“ģ„œ 예츔 ģ„±ėŠ„ģ„ ė†’ģ“ėŠ” 기법

      • ė™ģ¼ķ•œ ė°ģ“ķ„°ė”œė¶€ķ„° ė³µģ›ģ¶”ģ¶œģ„ 통핓 30개 ģ“ģƒģ˜ ė°ģ“ķ„°ģ…‹ģ„ ė§Œė“¤ģ–“ģ„œ 각각에 ģ˜ģ‚¬ź²°ģ •ė‚˜ė¬“ė„¼ ģ ģšÆģ•ˆ ė’¤ ķ•™ģŠµ 결과넼 ģ·Øķ•©ķ•˜ėŠ” ė°©ģ‹ģœ¼ė”œ ė™ģž‘

References

  • Theoretical Explanation

    • https://bkshin.tistory.com/entry/%EB%A8%B8%EC%8B%A0%EB%9F%AC%EB%8B%9D-4-%EA%B2%B0%EC%A0%95-%ED%8A%B8%EB%A6%ACDecision-Tree

    • https://ratsgo.github.io/machine%20learning/2017/03/26/tree/

  • Python Implementation of Decision Tree

    • https://towardsdatascience.com/construct-a-decision-tree-and-how-to-deal-with-overfitting-f907efc1492d

  • Scikit-learn documentation

    • https://scikit-learn.org/stable/modules/tree.html

  • MATHLAB Example

    • fitctree & fitrtree (instruction & algorithm)

      • https://kr.mathworks.com/help/stats/fitctree.html

      • https://kr.mathworks.com/help/stats/fitrtree.html

    • View Decision Tree

      • https://kr.mathworks.com/help/stats/view-decision-tree.html

    • Prediction Using Classification and Regression Trees

      • https://kr.mathworks.com/help/stats/prediction-using-classification-and-regression-trees.html

Last updated

Was this helpful?