공부 기록
ML(0813_day8) - 결정 트리 본문
결정 트리¶
In [3]:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier
In [4]:
iris = load_iris()
X = iris.data[:, 2:] # petal length, petal width
y = iris.target
In [8]:
tree_clf = DecisionTreeClassifier(max_depth=2, random_state=42)
tree_clf.fit(X, y)
Out[8]:
DecisionTreeClassifier(max_depth=2, random_state=42)
In [9]:
from sklearn.tree import export_graphviz
In [13]:
export_graphviz(tree_clf,
out_file="iris_tree.dot",
class_names=iris.target_names,
feature_names=iris.feature_names[2:],
rounded=True,
filled=True)
In [14]:
import graphviz
with open("iris_tree.dot") as f:
dot_graph = f.read()
graphviz.Source(dot_graph)
Out[14]:
In [ ]:
'playdata' 카테고리의 다른 글
ML(0816_day9) - 결정 트리 (0) | 2021.08.16 |
---|---|
ML(0812_day7) - 선형 회귀 (0) | 2021.08.13 |
ML(0813_day8) - 실습_붓꽃 데이터 품종 예측하기(로지스틱 회귀, 소프트맥스 회귀) (0) | 2021.08.13 |
ML(0813_day8) - 실습_Predict survival on the Titanic- using scikit-learn(모델 훈련) (0) | 2021.08.13 |
ML(0812_day7) - 실습_보스톤 주택 가격 예측(선형 회귀) (0) | 2021.08.13 |
Comments