<jupyter_start><jupyter_text>TSFs Task 6 by <NAME>  Prediction using Decision Tree Algorithm<jupyter_code>import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib 
import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split,cross_val_score
from sklearn.metrics import accuracy_score,confusion_matrix
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree

from sklearn import datasets
data = pd.read_csv("Iris.csv")
print('Data Saved and Loaded Successfully')
data.sample(5)<jupyter_output><empty_output><jupyter_text>**Basic Insights of the Data**<jupyter_code>data.head()
data.info()
data.describe()
data.isnull().sum()<jupyter_output><empty_output><jupyter_text>**Label Encoding**<jupyter_code>from sklearn.preprocessing import LabelEncoder

lb_make = LabelEncoder()
data['spc_code'] = lb_make.fit_transform(data.Species)
data.head()<jupyter_output><empty_output><jupyter_text>**Data Visualization**<jupyter_code>ax = data[data.Species=='Iris-setosa'].plot.scatter(x='SepalLengthCm', y='SepalWidthCm', 
                                                    color='red', label='setosa')
data[data.Species=='Iris-versicolor'].plot.scatter(x='SepalLengthCm', y='SepalWidthCm', 
                                                color='brown', label='versicolor', ax=ax)
data[data.Species=='Iris-virginica'].plot.scatter(x='SepalLengthCm', y='SepalWidthCm', 
                                                color='blue', label='virginica', ax=ax)
ax.set_title("scatter")
ax = data[data.Species=='Iris-setosa'].plot.scatter(x='PetalLengthCm', y='PetalWidthCm', 
                                                    color='red', label='setosa')
data[data.Species=='Iris-versicolor'].plot.scatter(x='PetalLengthCm', y='PetalWidthCm', 
                                                color='brown', label='versicolor', ax=ax)
data[data.Species=='Iris-virginica'].plot.scatter(x='PetalLengthCm', y='PetalWidthCm', 
                                                color='blue', label='virginica', ax=ax)
ax.set_title("scatter")
sns.set()
sns.pairplot(data[['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species']],hue="Species", diag_kind="kde")<jupyter_output><empty_output><jupyter_text>**Train, Test, Split and Modelling**<jupyter_code>X = data.iloc[:,1:5].values
y = data['spc_code'].values
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.10,random_state=0)

X_train.shape,X_test.shape,y_train.shape,y_test.shape
clf = DecisionTreeClassifier()
clf.fit(X_train,y_train)
pred = clf.predict(X_test)

df = pd.DataFrame({"Orignal":y_test,'Predicted':pred})
df
acc = accuracy_score(y_test, pred)
con_mat = confusion_matrix(y_test, pred, [0, 1])
print('We got an accuracy score of : {} %'.format(acc*100))
sns.heatmap(con_mat,annot=True)
print('\n CONFUSION MATRIX :')
plt.show()<jupyter_output>We got an accuracy score of : 100.0 %

 CONFUSION MATRIX :
{'fraction_non_alphanumeric': 0.1441196464989803, 'fraction_numerical': 0.005778382053025153, 'mean_word_length': 4.3901098901098905, 'pattern_counts': {'":': 1, '<': 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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '616558', 'license': 'Unlicense', 'n_tokens_mistral': 1045, 'n_tokens_neox': 1005, 'n_words': 156, 'path': 'Task 6.ipynb', 'repo_name': 'vision266/TSF', 'size': '2946'}