# 決策樹 Decision Trees

* 以樹狀來表達資料流 (tree-based) 的一種監督式機器學習(supervised machine learning)演算法。
* 使用**分治法 (divide and conquer)：**&#x8B93;資料從樹根 (root) 開始，根據特定條件選擇最佳的分支屬性，而在每個節點形成分支，直到所有資料都被指定到葉節點 (leaf node) 為止。

## 考量

* 訓練資料愈多愈好。
* 可選擇的變數愈多愈好。
* 好的決策樹應該精簡，只預測最少數量的問題。

製作決策樹有不同考量，依照以下作法不同，而有不同的演算法，如 `C5, CART,CHAID`等。

* 分支判準 splitting criteria
* 停止條件
* 修剪時機

```
# Import required library
library('rpart')

# Fitting model (growing tree)
fit <- rpart(y_train ~ ., data = x, method="class")
summary(fit)

# Predict Output
predicted <- predict(fit, x_test)
```


---

# Agent Instructions: 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:

```
GET https://lab-of-ontologies-language-proce.gitbook.io/ladsbook/partiji-chu-zhi-shi/machine_learning/jue-ce-shu-decisiontrees.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
