* 의사결정 나무
- 데이터 분로를 나누는 지도학습의 분류에 해당하는 모델
- 연속적인 질문을 통해 결과를 제공하는 예측모델로서 사람이 조건에 따라 행동하고 판단하는 것을 머신러닝에 적용
- 지도 학습의 분류가 어떻게 이루어지는지 잘 알려줌
#붗꽃 데이터를 이용하여 의사 결정나무를 만드는 코드
from sklearn import datasets
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
def main():
# iris 데이터 로드
dataset = datasets.load_iris()
features = dataset.data
targets = dataset.target;
# 꽃잎의 길이와 넓이 정보만 특징으로 사용 (2)
petal_features = features[:, 2:]
# 의사결정 모델 클래스 생성 (3)
#cIris = DecisionTreeClassifier(criterion='gini', max_depth=3)
cIris = DecisionTreeClassifier(criterion='entropy', max_depth=3)
# 모델을 훈련 (4)
cIris.fit(petal_features, targets)
# DOT 언어의 형식으로 결정 나무의 형태를 출력한다.
with open('iris-dtree.dot', mode='w') as f:
tree.export_graphviz(cIris, out_file=f)
if __name__ == '__main__' :
main()
