Created
October 22, 2019 01:55
-
-
Save Lucs1590/dd49aa5f732f6683026a88c8a8e493f7 to your computer and use it in GitHub Desktop.
Plotagem de arvore de decisão a partir do dataset de iris
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sklearn.datasets as datasets | |
import pandas as pd | |
from sklearn.tree import DecisionTreeClassifier | |
from sklearn.externals.six import StringIO | |
from IPython.display import Image | |
from sklearn.tree import export_graphviz | |
import pydotplus | |
iris = datasets.load_iris() | |
df = pd.DataFrame(iris.data, columns=iris.feature_names) | |
y = iris.target | |
dtree = DecisionTreeClassifier() | |
dtree.fit(df, y) | |
dot_data = StringIO() | |
export_graphviz(dtree, out_file=dot_data, | |
filled=True, rounded=True, | |
special_characters=True) | |
graph = pydotplus.graph_from_dot_data(dot_data.getvalue()) | |
img = Image(graph.create_png()) | |
with open("arvore.png", "wb") as png: | |
png.write(graph.create_png()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment