결정 트리
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
결정 포레스트 모델은 결정 트리로 구성됩니다. 결정 포레스트 학습 알고리즘 (예: 랜덤 포레스트)은 적어도 부분적으로 결정 트리의 학습에 의존합니다.
이 과정에서는 작은 예시 데이터 세트를 살펴보고 단일 의사결정 트리가 학습되는 방식을 알아봅니다. 다음 섹션에서는 결정 트리를 결합하여 결정 숲을 학습하는 방법을 알아봅니다.
YDF에서 CART 학습기를 사용하여 개별 결정 트리 모델을 학습합니다.
# https://ydf.readthedocs.io/en/latest/py_api/CartLearner
import ydf
model = ydf.CartLearner(label="my_label").train(dataset)
모델
결정 트리는 트리 모양으로 계층적으로 구성된 '질문' 모음으로 구성된 모델입니다. 이러한 질문을 일반적으로 조건, 분할 또는 테스트라고 합니다. 이 클래스에서는 '조건'이라는 용어를 사용합니다. 리프가 아닌 각 노드에는 조건이 포함되고 각 리프 노드에는 예측이 포함됩니다.
식물학적 나무는 일반적으로 뿌리가 아래쪽에 있으면서 자라지만 결정 트리는 일반적으로 뿌리 (첫 번째 노드)가 맨 위에 표시됩니다.

그림 1. 간단한 분류 결정 트리 녹색의 범례는 결정 트리의 일부가 아닙니다.
결정 트리 모델의 추론은 조건에 따라 예시를 루트 (상단)에서 리프 노드 (하단) 중 하나로 라우팅하여 계산됩니다. 도달한 리프의 값이 결정 트리의 예측입니다.
방문한 노드 집합을 추론 경로라고 합니다. 예를 들어 다음과 같은 지형지물 값을 고려해 보겠습니다.
예측 결과는 dog입니다. 추론 경로는 다음과 같습니다.
- num_legs ≥ 3 → 예
- num_eyes ≥ 3 → 아니요

그림 2 예시 *{num_legs : 4, num_eyes : 2}*에서 리프 *dog*로 이어지는 추론 경로입니다.
이전 예에서 결정 트리의 리프에는 분류 예측이 포함됩니다. 즉, 각 리프에는 가능한 종 집합 중 하나의 동물 종이 포함됩니다.
마찬가지로 결정 트리는 리프에 회귀 예측 (숫자 값)을 라벨링하여 숫자 값을 예측할 수 있습니다. 예를 들어 다음 결정 트리는 동물의 귀여움 점수를 0~10 사이의 숫자로 예측합니다.

그림 3. 수치 예측을 실행하는 결정 트리입니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[null,null,["최종 업데이트: 2025-07-27(UTC)"],[[["\u003cp\u003eDecision forest models are built using decision trees, with algorithms like random forests relying on the learning of individual decision trees.\u003c/p\u003e\n"],["\u003cp\u003eA decision tree model uses a hierarchical structure of conditions to route an example from the root to a leaf node, where the leaf's value represents the prediction.\u003c/p\u003e\n"],["\u003cp\u003eDecision trees can be used for both classification tasks, predicting categories like animal species, and regression tasks, predicting numerical values like cuteness scores.\u003c/p\u003e\n"],["\u003cp\u003eYDF, a specific tool, utilizes the CART learner to train individual decision tree models.\u003c/p\u003e\n"]]],[],null,["# Decision trees\n\n\u003cbr /\u003e\n\nDecision forest models are composed of decision trees. Decision forest\nlearning algorithms (like random forests) rely, at least in part, on the\nlearning of decision trees.\n\nIn this section of the course, you will study a small example dataset, and learn\nhow a single decision tree is trained. In the next sections, you will learn how\ndecision trees are combined to train decision forests. \nYDF Code\n\nIn YDF, use the CART learner to train individual decision tree models: \n\n```python\n# https://ydf.readthedocs.io/en/latest/py_api/CartLearner\nimport ydf\nmodel = ydf.CartLearner(label=\"my_label\").train(dataset)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThe model\n---------\n\nA **decision tree** is a model composed of a collection of \"questions\" organized\nhierarchically in the shape of a tree. The questions are usually called a\n**condition,** a **split** , or a **test.** We will use the term \"condition\" in\nthis class. Each non-leaf node contains a condition, and each leaf node contains\na prediction.\n\nBotanical trees generally grow with the root at the bottom; however, decision\ntrees are usually represented with the **root** (the first node) at the top.\n\n**Figure 1. A simple classification decision tree. The legend in green is not part\nof the decision tree.**\n\nInference of a decision tree model is computed by routing an example from the\nroot (at the top) to one of the leaf nodes (at the bottom) according to the\nconditions. The value of the reached leaf is the decision tree's prediction.\nThe set of visited nodes is called the **inference path**. For example,\nconsider the following feature values:\n\n| num_legs | num_eyes |\n|----------|----------|\n| 4 | 2 |\n\nThe prediction would be *dog*. The inference path would be:\n\n1. num_legs ≥ 3 → Yes\n2. num_eyes ≥ 3 → No\n\n**Figure 2. The inference path that culminates in the leaf \\*dog\\* on the example\n\\*{num_legs : 4, num_eyes : 2}\\*.**\n\nIn the previous example, the leaves of the decision tree contain classification\npredictions; that is, each leaf contains an animal species among a set\nof possible species.\n\nSimilarly, decision trees can predict numerical values by labeling leaves with\nregressive predictions (numerical values). For example, the following decision\ntree predicts a numerical cuteness score of an animal between 0 and 10.\n\n**Figure 3. A decision tree that makes numerical prediction.**"]]