Creating and Visualizing Decision Trees with Python

import sklearn.datasets as datasets
import pandas as pd
iris=datasets.load_iris()
df=pd.DataFrame(iris.data, columns=iris.feature_names)
y=iris.target
from sklearn.tree import DecisionTreeClassifier
dtree=DecisionTreeClassifier()
dtree.fit(df,y)
from sklearn.externals.six import StringIO  
from IPython.display import Image
from sklearn.tree import export_graphviz
import pydotplus
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())
Image(graph.create_png())

--

--

--

Poker player turned data scientist

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Russell

Russell

Poker player turned data scientist

More from Medium

End-to-End Customer Segmentation Project with Python

Using Census and Housing Data to Predict Housing Prices in Pittsburgh: EDA, Analysis & Conclusion

Extractive Text Summarization with Python

Ponder with Pandas — Unstructured Text to Variable-Length Records in Excel format