-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDT.py
33 lines (25 loc) · 1.08 KB
/
DT.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from sklearn import tree
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.tree import export_graphviz
import numpy as np
import pydotplus
from IPython.display import Image
iris = datasets.load_iris()
X = iris.data[:, [2, 3]]
y = iris.target
# 자동으로 데이터셋을 분리해주는 함수
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
# 데이터 표준화 작업
sc = StandardScaler()
sc.fit(X_train)
# 표준화된 데이터셋
X_train_std = sc.transform(X_train)
X_test_std = sc.transform(X_test)
iris_tree = tree.DecisionTreeClassifier(criterion='entropy', max_depth=10, random_state=0)
iris_tree.fit(X_train, y_train)
dot_data = export_graphviz(iris_tree, out_file='D:\package\\dt.dot', feature_names=['petal length', 'petal width'],
class_names=iris.target_names, filled=True, rounded=True, special_characters=True)
# graph = pydotplus.graph_from_dot_data(dot_data)
# Image(graph.create_png())