<jupyter_start><jupyter_text>**Prediction using Decision Tree Algorithm** Let's import everything we need<jupyter_code>import numpy as np 
import pandas as pd 
import os
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.metrics import accuracy_score,classification_report
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier,export_graphviz
data = pd.read_csv('/content/Iris.csv')
data.head(5)<jupyter_output><empty_output><jupyter_text>Visualizing the data<jupyter_code>plt.style.use('seaborn') 
plt.figure(figsize = (7,3))
data['Species'].value_counts().plot.bar(color = 'cyan')
plt.title('Iris Species')
plt.xlabel('Species')
plt.ylabel('Count')
plt.show()


##Let's make a pie chart
plt.style.use('_classic_test_patch') 
plt.figure(figsize = (7,3))
data['Species'].value_counts().plot.pie(explode=[0.1,0.1,0.1],autopct='%1.1f%%',shadow=False,cmap='Set3')
plt.title('Data Distribution')
plt.show()

plt.style.use('dark_background') 
plt.figure(figsize = (7,3))
sns.boxplot(x='Species',y='PetalLengthCm',data=data,order=['Iris-virginica','Iris-versicolor','Iris-setosa'],linewidth=2.5,orient='v',dodge=False,palette = 'Set1')
plt.title('Distribution of the Different species in our data')
plt.show()


plt.style.use('tableau-colorblind10') 
data.plot.area(y=['SepalLengthCm','SepalWidthCm','PetalLengthCm','PetalWidthCm'],alpha=0.4,cmap = 'Set3',figsize = (7,3))
plt.title('Distribution')
plt.show()
plt.style.use('tableau-colorblind10') 
plt.figure(figsize = (7,3))
sns.violinplot(x='Species',y='SepalLengthCm',data=data,palette = 'Set3')
plt.title('Distribution')
plt.show()
f, axes = plt.subplots(ncols = 3, figsize=(7, 3), sharex=True)
sns.despine(left=True)
sns.boxplot(x = data['SepalWidthCm'], ax=axes[0])
sns.distplot(a=data['SepalWidthCm'], kde=False, ax=axes[1])
sns.kdeplot(data=data['SepalWidthCm'], shade=True, ax=axes[2])
plt.tight_layout()
f, axes = plt.subplots(ncols = 3, figsize=(7, 3), sharex=True)
sns.despine(left=True)
sns.boxplot(x = data['SepalLengthCm'], ax=axes[0])
sns.distplot(a=data['SepalLengthCm'], kde=False, ax=axes[1])
sns.kdeplot(data=data['SepalLengthCm'], shade=True, ax=axes[2])
plt.tight_layout()
f, axes = plt.subplots(ncols = 3, figsize=(7, 3), sharex=True)
sns.despine(left=True)
sns.boxplot(x = data['PetalLengthCm'], ax=axes[0])
sns.distplot(a=data['PetalLengthCm'], kde=False, ax=axes[1])
sns.kdeplot(data=data['PetalLengthCm'], shade=True, ax=axes[2])
plt.tight_layout()
f, axes = plt.subplots(ncols = 3, figsize=(7, 3), sharex=True)
sns.despine(left=True)
sns.boxplot(x = data['PetalWidthCm'], ax=axes[0])
sns.distplot(a=data['PetalWidthCm'], kde=False, ax=axes[1])
sns.kdeplot(data=data['PetalWidthCm'], shade=True, ax=axes[2])
plt.tight_layout()<jupyter_output>/usr/local/lib/python3.6/dist-packages/seaborn/distributions.py:2551: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)<jupyter_text>Let's prepare the data<jupyter_code>X_train,X_val,y_train,y_val=train_test_split(data.iloc[:,1:-1],data.iloc[:,-1],test_size=0.3,random_state=69)
print(X_train.shape)
print(y_train.shape)
print(X_val.shape)
print(y_val.shape)


mymodel=DecisionTreeClassifier()
mymodel.fit(X_train,y_train)
y_pred=mymodel.predict(X_val)


print(accuracy_score(y_pred,y_val))
print(classification_report(y_pred,y_val))
plt.style.use('classic')
from sklearn import tree
fig = plt.figure(figsize=(10,8))
_ = tree.plot_tree(mymodel,
                   feature_names=['SepalLengthCm','SepalWidthCm','PetalLengthCm','PetalWidthCm'],  
                   class_names=['Iris-setosa','Iris-versicolor','Iris-virginica'],
                   filled=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17137764196587726, 'fraction_numerical': 0.018079959256429846, 'mean_word_length': 7.866817155756208, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '327438', 'license': 'CC0-1.0', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1521, 'n_words': 228, 'path': 'TSF-TASK6/TSF_TASK6.ipynb', 'repo_name': 'pksenpai/TSF_Internship_Tasks', 'size': '3927'}