<jupyter_start><jupyter_text>GRIP The Sparks Foundation(TSF)Task - 6 Prediction using Decision Tree AlgorithmIn this task,- Create the Decision Tree classifier and visualize it graphically.- The purpose is if we feed any new data to this classifier, it would be able to predict the right class accordingly.Steps - - Step 1 - Importing the Library - Step 2 - Importing the Dataset - Step 3 - Data Exploration - Step 4 - Define the Decision Tree Algorithm - Step 5 - Visualizing the Decision TreeCreated by - <NAME> STEP 1 - Importing the LibraryIn this step, we will import the Libraries.<jupyter_code># Importing libraries in Python
import sklearn.datasets as datasets
import pandas as pd<jupyter_output><empty_output><jupyter_text>STEP 2 - Importing the Dataset<jupyter_code># Loading the iris dataset
iris=datasets.load_iris()

# Forming the iris dataframe
iris_df=pd.DataFrame(iris.data, columns=iris.feature_names)
#first five rows of dataset
iris_df.head()
#last five rows of dataset
iris_df.tail()
y=iris.target
y<jupyter_output><empty_output><jupyter_text>STEP 3 - Data Exploration<jupyter_code>#shape of dataset
iris_df.shape
#columns names of the dataset 
iris_df.columns
#info of the dataset 
iris_df.info()
#summary of the data
iris_df.describe()<jupyter_output><empty_output><jupyter_text>STEP 4 - Define the Decision Tree Algorithm<jupyter_code># Defining the decision tree algorithm
from sklearn.tree import DecisionTreeClassifier
dtree=DecisionTreeClassifier()
dtree.fit(iris_df,y)

print('Decision Tree Classifer Created')<jupyter_output>Decision Tree Classifer Created<jupyter_text>STEP 5 - Visualizing the Decision Tree<jupyter_code># Install required libraries
!pip install pydotplus
!apt-get install graphviz -y
# Import necessary libraries for graph viz
from sklearn.externals.six import StringIO  
from IPython.display import Image  
from sklearn.tree import export_graphviz
import pydotplus

# Visualize the graph
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())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07152436298614215, 'fraction_numerical': 0.0049172999552972736, 'mean_word_length': 5.6805970149253735, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '621588', 'license': 'MIT', 'n_tokens_mistral': 728, 'n_tokens_neox': 692, 'n_words': 220, 'path': 'TSF_Task_6.ipynb', 'repo_name': 'abhijeetraj22/TSF-GRIP_Tasks', 'size': '2252'}