<jupyter_start><jupyter_text>Prediction using Decision Tree Algorithm Objective: Create the Decision Tree classifier and visualize it graphically. Author- <NAME>  Importing The Libraries<jupyter_code>import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import confusion_matrix, classification_report
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import accuracy_score
from six import StringIO  
from IPython.display import Image  
from sklearn import tree
import pydotplus<jupyter_output><empty_output><jupyter_text>READING THE DATA AND FINDING OUT THE UNIQUE SPECIES<jupyter_code>df=pd.read_csv('iris.csv')
df['Species'].unique()<jupyter_output><empty_output><jupyter_text>GATHERING INFO ABOUT THE DATASET<jupyter_code>df.describe()<jupyter_output><empty_output><jupyter_text>USING LABEL ENCODER FOR CATEGORICAL FEATURES<jupyter_code>lr=LabelEncoder()
df['Species']=lr.fit_transform(df['Species'])<jupyter_output><empty_output><jupyter_text>SPLITTING THE DATA FOR TRAINING AND TESTING<jupyter_code>X=df.drop(['Species','Id'],axis=1)
y=df['Species']
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=0)<jupyter_output><empty_output><jupyter_text>FINDING OUT THE ACCURACY USING DECISION TREE CLASSIFIER<jupyter_code>DT= DecisionTreeClassifier()
Z=DT.fit(X_train,y_train)
predict=DT.predict(X_test)
print(classification_report(y_test,predict))
cm2=accuracy_score(y_test,predict)

print(cm2)
print(confusion_matrix(y_test,predict))<jupyter_output>precision    recall  f1-score   support

           0       1.00      1.00      1.00        11
           1       1.00      1.00      1.00        13
           2       1.00      1.00      1.00         6

    accuracy                           1.00        30
   macro avg       1.00      1.00      1.00        30
weighted avg       1.00      1.00      1.00        30

1.0
[[11  0  0]
 [ 0 13  0]
 [ 0  0  6]]<jupyter_text>VISUALISING THE DECISION TREE<jupyter_code>new_col=df.select_dtypes(include=float).columns
dot_data = StringIO()
tree.export_graphviz(DT, out_file=dot_data, feature_names=new_col,
                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.09144295302013423, 'fraction_numerical': 0.034395973154362415, 'mean_word_length': 4.3475336322869955, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '270991', 'license': 'MIT', 'n_tokens_mistral': 883, 'n_tokens_neox': 830, 'n_words': 156, 'path': 'Machine Learning/decision tree algorithm.ipynb', 'repo_name': 'Aloknegi1904/HacktoberFest2021-6', 'size': '2389'}