<jupyter_start><jupyter_text>Name: <NAME> adityavardhan GRIP@TSF NOVEMBER BATCH<jupyter_code>import pandas as pd
import numpy as np
data_frame = pd.read_csv('Iris.csv')
data_frame.head()
data_frame.isnull().sum()
data_frame.dtypes<jupyter_output><empty_output><jupyter_text>Analysis  Outlier Checking<jupyter_code>import matplotlib.pyplot as plt
plt.figure(figsize=(8,7),dpi=120)
plt.subplot(2,2,1)
plt.boxplot(data_frame["SepalLengthCm"])
plt.title("Sepal Length in cm")
plt.subplot(2,2,2)
plt.boxplot(data_frame["SepalWidthCm"])
plt.title("Sepal Width in cm")
plt.subplot(2,2,3)
plt.boxplot(data_frame["PetalLengthCm"])
plt.title("Petal Length in cm")
plt.subplot(2,2,4)
plt.boxplot(data_frame["PetalWidthCm"])
plt.title("Petal Width in cm")<jupyter_output><empty_output><jupyter_text>ObservationWe found an outlier in Sepal Width hence we remove those outliers to get correct predictions<jupyter_code>data_frame = data_frame.drop(data_frame[data_frame["SepalWidthCm"]>4.0].index)

data_frame = data_frame.drop(data_frame[data_frame["SepalWidthCm"]<2.1].index)
plt.figure(figsize=(8,7),dpi=120)
plt.subplot(2,2,1)
plt.boxplot(data_frame["SepalLengthCm"])
plt.title("Sepal Length in cm")
plt.subplot(2,2,2)
plt.boxplot(data_frame["SepalWidthCm"])
plt.title("Sepal Width in cm")
plt.subplot(2,2,3)
plt.boxplot(data_frame["PetalLengthCm"])
plt.title("Petal Length in cm")
plt.subplot(2,2,4)
plt.boxplot(data_frame["PetalWidthCm"])
plt.title("Petal Width in cm")<jupyter_output><empty_output><jupyter_text>Sepal length vs Sepal Width Comparison<jupyter_code>fig = plt.figure()
ax = fig.add_subplot(1,1,1)
colors = {'Iris-setosa':'red', 'Iris-versicolor':'blue', 'Iris-virginica':'green'}
ax.scatter(data_frame["SepalLengthCm"],data_frame["SepalWidthCm"],c=data_frame['Species'].apply(lambda x: colors[x]))
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
indep = data_frame.drop(["Species"],axis=1)
dep = data_frame["Species"]
train_x,test_x,train_y,test_y = train_test_split(indep,dep,random_state=42,stratify=dep)
train_x.head()
test_x.head()
train_y.value_counts()/len(train_y)
test_y.value_counts()/len(test_y)
model = DecisionTreeClassifier()
model.fit(train_x,train_y)
pred = model.predict(test_x)
from sklearn.metrics import confusion_matrix
confusion_matrix(pred,test_y)
from sklearn import tree
tree.export_graphviz(model,out_file='tree.dot',feature_names=train_x.columns,max_depth=2,filled=True)
import graphviz
with open("tree.dot") as f:
    dot_graph = f.read()
graphviz.Source(dot_graph)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1480046493607129, 'fraction_numerical': 0.01743510267338241, 'mean_word_length': 10.226086956521739, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '90132', 'license': 'MIT', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1014, 'n_words': 148, 'path': 'Decision Tree task 6/DT Classifier.ipynb', 'repo_name': 'AVS18/grip-sparks-foundation-all', 'size': '2580'}