# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] id="tc4Xb8Fyz9Re"
# <NAME>
# -

#                                             IMPORTING LIBRARIES

# + id="6Fvv3zM70hIu"
import sklearn.datasets as datasets
import pandas as pd

# + [markdown] id="7r_HJVUW0jBa"
#                                               IMPORTING DATASET

# + colab={"base_uri": "https://localhost:8080/"} id="-9bkxQwD0psJ" outputId="e6724b86-9f05-4001-93b9-c4d17196006c"
iris=datasets.load_iris()
df=pd.DataFrame(iris.data, columns=iris.feature_names)
print(df.head(5))
y=iris.target
print(y)

# + [markdown] id="yZc6lfeT1Eod"
#                                            THE DECISION TREE ALGORITHUM

# + colab={"base_uri": "https://localhost:8080/"} id="rDaUKqfd1Le6" outputId="9f65be7c-e108-446b-f5e4-ee8854c6bedd"
from sklearn.tree import DecisionTreeClassifier
dtree=DecisionTreeClassifier()
dtree.fit(df,y)

# + [markdown] id="CERKYXMF1RRI"
#                                           Visualize the Decision Tree

# + [markdown] id="rGacOwWu1Z_Q"
# >>Installing the required libraries

# + colab={"base_uri": "https://localhost:8080/"} id="m1XpW0ND1fas" outputId="d532fcb8-8794-447b-bc2f-5ea029ef984b"
# !pip install pydotplus
# !apt-get install graphviz -y

# + [markdown] id="-yxgR-HY199i"
# >>Visualize the graph

# + colab={"base_uri": "https://localhost:8080/", "height": 802} id="cqWT0jWJ10nK" outputId="5afdcc36-ba60-431c-fd9c-3fe7d684132c"
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, feature_names=iris.feature_names,  
                filled=True, rounded=True,
                special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())  
Image(graph.create_png())

StarcoderdataJupyterScriptsDedupFiltered