> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/python/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/python/chapter-2courses/21python-for-data-science-and-machine-learning-bootcamp/dsd/21141introduction-of-tree-methods.md).

# 2.1.14.1.Introduction of tree methods

## 1.Introduction

* 會使用決策樹的例子
  * 有一位打球的朋友, 有時會出現而有時不會, 導致他不會出現的因素有很多, 例如天氣, 溫度, 濕度等
  * 於是我們想找出這些因素與最後對方是否會出現
  * 利用這些因素的資料來預測對方是否會出現, 方法之一就是使用決策樹
* 決策樹

  &#x20; ![](/files/-M4M0SYdmB31kylImFpo)

  * Nodes
    * 因為某Attribute的值而分割 (split)
  * Edges
    * Next node的輸出值
  * Root
    * 第一個split的node
  * Leaves
    * 做預測的**Terminal node**

## 2.分割背後的直覺

* Best split
  * 在資料中最能夠左右結果的因子
* Entropy, information gain
  * 可以協助找出**best split**的數學指標
* Random forest
  * Decision tree的缺點是無法趨向最佳的預測精度 (predictive accuracy)
  * 使用一群隨機在每個split所找出的tree, 特性是變異度高
  * Random force
    * [Bagging](https://zh.wikipedia.org/wiki/Bagging%E7%AE%97%E6%B3%95)是一個常用來降低機器學習算法的變異數的方式, 通常是在所有的隨機樹(p)中挑選m顆
    * 避免單一具領導性的feature造成樹之間的高度相關性

## 3.參考資料

* Refer to Chapter 8. Introduction to Statistical Learning


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://jen-hsuan-hsieh.gitbook.io/python/chapter-2courses/21python-for-data-science-and-machine-learning-bootcamp/dsd/21141introduction-of-tree-methods.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
