Technologische_Grundlagen/Iris/iris_identification_DT.ipynb

1141 lines
188 KiB
Plaintext
Raw Permalink Normal View History

2024-09-27 07:00:19 +00:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "9e96a1dd-303c-4920-8d24-d5d7e58dc02d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>sepal length (cm)</th>\n",
" <th>sepal width (cm)</th>\n",
" <th>petal length (cm)</th>\n",
" <th>petal width (cm)</th>\n",
" <th>Species</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>5.1</td>\n",
" <td>3.5</td>\n",
" <td>1.4</td>\n",
" <td>0.2</td>\n",
" <td>Iris-setosa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>4.9</td>\n",
" <td>3.0</td>\n",
" <td>1.4</td>\n",
" <td>0.2</td>\n",
" <td>Iris-setosa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>4.7</td>\n",
" <td>3.2</td>\n",
" <td>1.3</td>\n",
" <td>0.2</td>\n",
" <td>Iris-setosa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4.6</td>\n",
" <td>3.1</td>\n",
" <td>1.5</td>\n",
" <td>0.2</td>\n",
" <td>Iris-setosa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5.0</td>\n",
" <td>3.6</td>\n",
" <td>1.4</td>\n",
" <td>0.2</td>\n",
" <td>Iris-setosa</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" sepal length (cm) sepal width (cm) petal length (cm) petal width (cm) \\\n",
"0 5.1 3.5 1.4 0.2 \n",
"1 4.9 3.0 1.4 0.2 \n",
"2 4.7 3.2 1.3 0.2 \n",
"3 4.6 3.1 1.5 0.2 \n",
"4 5.0 3.6 1.4 0.2 \n",
"\n",
" Species \n",
"0 Iris-setosa \n",
"1 Iris-setosa \n",
"2 Iris-setosa \n",
"3 Iris-setosa \n",
"4 Iris-setosa "
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"# Loading the iris dataset\n",
"url = \"https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data\"\n",
"df = pd.read_csv(url, header=None, names=['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)',\n",
" 'petal width (cm)', 'Species'])\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "1a8f6c2f-d63a-4fc0-9e06-3c360e451852",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(150, 5)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# To know number of rows and collumns\n",
"df.shape"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "dc5283cb-d268-4373-99d1-94cf90c33edd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 150 entries, 0 to 149\n",
"Data columns (total 5 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 sepal length (cm) 150 non-null float64\n",
" 1 sepal width (cm) 150 non-null float64\n",
" 2 petal length (cm) 150 non-null float64\n",
" 3 petal width (cm) 150 non-null float64\n",
" 4 Species 150 non-null object \n",
"dtypes: float64(4), object(1)\n",
"memory usage: 6.0+ KB\n"
]
}
],
"source": [
"# Check the dataframe information\n",
"df.info()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "68c02ddc-9a88-45b1-8f86-9b2c9ebfc713",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"sepal length (cm) 0\n",
"sepal width (cm) 0\n",
"petal length (cm) 0\n",
"petal width (cm) 0\n",
"Species 0\n",
"dtype: int64"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# To find if any null value is present\n",
"df.isnull().sum()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "15fa05e3-9e35-44dc-a053-4021f64ec00b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>count</th>\n",
" <th>mean</th>\n",
" <th>std</th>\n",
" <th>min</th>\n",
" <th>25%</th>\n",
" <th>50%</th>\n",
" <th>75%</th>\n",
" <th>max</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>sepal length (cm)</th>\n",
" <td>150.0</td>\n",
" <td>5.843333</td>\n",
" <td>0.828066</td>\n",
" <td>4.3</td>\n",
" <td>5.1</td>\n",
" <td>5.80</td>\n",
" <td>6.4</td>\n",
" <td>7.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>sepal width (cm)</th>\n",
" <td>150.0</td>\n",
" <td>3.054000</td>\n",
" <td>0.433594</td>\n",
" <td>2.0</td>\n",
" <td>2.8</td>\n",
" <td>3.00</td>\n",
" <td>3.3</td>\n",
" <td>4.4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>petal length (cm)</th>\n",
" <td>150.0</td>\n",
" <td>3.758667</td>\n",
" <td>1.764420</td>\n",
" <td>1.0</td>\n",
" <td>1.6</td>\n",
" <td>4.35</td>\n",
" <td>5.1</td>\n",
" <td>6.9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>petal width (cm)</th>\n",
" <td>150.0</td>\n",
" <td>1.198667</td>\n",
" <td>0.763161</td>\n",
" <td>0.1</td>\n",
" <td>0.3</td>\n",
" <td>1.30</td>\n",
" <td>1.8</td>\n",
" <td>2.5</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" count mean std min 25% 50% 75% max\n",
"sepal length (cm) 150.0 5.843333 0.828066 4.3 5.1 5.80 6.4 7.9\n",
"sepal width (cm) 150.0 3.054000 0.433594 2.0 2.8 3.00 3.3 4.4\n",
"petal length (cm) 150.0 3.758667 1.764420 1.0 1.6 4.35 5.1 6.9\n",
"petal width (cm) 150.0 1.198667 0.763161 0.1 0.3 1.30 1.8 2.5"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# To see summary statistics\n",
"df.describe().T"
]
},
{
"cell_type": "markdown",
"id": "25225fd1-313b-4dd7-81e4-63e8a09490db",
"metadata": {},
"source": [
"### other options for palettes \n",
"\n",
"- \"PRGn\" \n",
"- \"flare\"\n",
"- \"colorblind\""
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "6baff895-78f5-4c65-a804-32b372f95814",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABgcAAAMzCAYAAACC5MK2AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8g+/7EAAAACXBIWXMAAA9hAAAPYQGoP6dpAACat0lEQVR4nOz9e5hWZaE//r+H04DKIYjDkBw9oKIoiSaaoJK4xTSTbWmkpqWbJDWJKDxuTMUKFUkFMQQJD+1Cy7aH1BLIPpiSGGZopgTEBslU8DgIzO+Pvs6viYMzCiyY5/W6rnXJute9nnk/XTEPM++17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ueWCAQAA/Ju2bdvW2L/qqquyyy67pH///gUlAgCAD67QcgAAAGB7tHr16kyfPj3Dhw9PWVnZRudVVlamsrKyen/VqlVbIx4AALyvQp85AAAAsD362c9+ltdeey1f+tKXNjlvzJgxadmyZfXWqVOnrRMQAADeh3IAAACgjiZPnpyjjz46HTt23OS8UaNGZeXKldXbkiVLtlJCAADYNMsKAQAA1MGiRYvy8MMP56677nrfueXl5SkvL98KqQAAoG7cOQAAAFAHU6ZMSbt27XLMMccUHQUAAD4w5QAAAEAtrVu3LlOmTMlpp52WRo3ciA0AwPZLOQAAAFBLDz/8cBYvXpwzzjij6CgAAPChuNQFAACglgYOHJiqqqqiYwAAwIemHAAA+BDWrl2b+fPn55VXXknr1q3Tq1evNGzYsOhYAAAAsEnKAQCAD2j27Nm58cYbs3z58uqxDh065Oyzz06/fv0KTAYAwJYyZsyY3HXXXXn22WfTrFmzHHzwwfnud7+bHj16bPScmTNn5vDDD19vfMGCBdljjz22ZFyAjfLMAQCAD2D27Nm59NJL071799xwww257777csMNN6R79+659NJLM3v27KIjAgCwBcyaNSvDhg3LY489loceeihr1qzJwIED8+abb77vuc8991yWLVtWve22225bITHAhrlzAACgjtauXZsbb7wxffv2zeWXX54GDf55vUXPnj1z+eWX56KLLsqECRNyyCGHWGIIAKCeeeCBB2rsT5kyJe3atcvvf//79717tF27dmnVqtUWTAdQe8oB6uydd97J4sWLi45BHXTu3DlNmzYtOgZAvTF//vwsX748F198cXUx8J4GDRpkyJAhGTZsWObPn5/evXsXlBKg/vGzyPbHzyKUgpUrVyZJWrdu/b5ze/funXfeeSd77bVXLrroog0uNfSeysrKVFZWVu+vWrXqw4ctYT5Dtk8+R7Ys5QB1tnjx4px11llFx6AOJk2alN13373oGAD1xiuvvJIk6dat2waPvzf+3jwANg8/i2x//CxCfVdVVZXhw4fnk5/8ZPbee++NzquoqMikSZOy//77p7KyMj/60Y8yYMCAzJw5c6N3G4wZMyajR4/eUtFLjs+Q7ZPPkS1LOUCdde7cOZMmTSo6xma1aNGiXHHFFbnwwgvTpUuXouNsdp07dy46AkC98t5VYQsXLkzPnj3XO75w4cIa8wDYPPwssv3xswj13de+9rXMnz8/jz766Cbn9ejRo8YDi/v27ZslS5Zk7NixGy0HRo0aleHDh1fvr1q1Kp06ddo8wUtQffwMSXyO8OEoB6izpk2b1tvGrkuXLvX2vQGw+fTq1SsdOnTIbbfdVuOZA0mybt263HbbbamoqEivXr0KTAlQ//hZBNiWnHPOObnnnnsye/bs7LzzznU+/6CDDsr06dM3ery8vDzl5eUfJiL/oj5/hiQ+R/hgGrz/FAAA/lXDhg1z9tlnZ86cObnooovyzDPP5K233sozzzyTiy66KHPmzMlXv/pVDyMGAKiHqqq
"text/plain": [
"<Figure size 1900x1000 with 4 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"#%matplotlib inline # inline render graphs below cell (but maybe not necessary anymore) \n",
"\n",
"columns = df.columns # my data has 4 columns.\n",
"\n",
"fig, ax = plt.subplots(ncols = 4, figsize=(19,10))\n",
"plt.subplots_adjust(wspace = 0.5) # wspace = width space\n",
"\n",
"for i in range(0,4):\n",
" s = sns.boxplot(ax = ax[i], data = df[columns[i]], showfliers = True)\n",
" ax[i].set_xlabel(columns[i])\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "32b155aa-a95b-438d-a0ee-0d1336bc462d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(146, 5)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
" # To remove outliers from 'sepal width (cm)'\n",
"q1 = df['sepal width (cm)'].quantile(0.25)\n",
"q3 = df['sepal width (cm)'].quantile(0.75)\n",
"iqr = q3 - q1\n",
"df = df[(df['sepal width (cm)'] >= q1-1.5*iqr) & (df['sepal width (cm)'] <= q3+1.5*iqr)]\n",
"df.shape # To find out the number of rows and column after outlier treatment"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "665e444d-3d65-4dc6-94c1-60fb0677dc77",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkAAAAGKCAYAAADkAf55AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8g+/7EAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAsFElEQVR4nO3df1iUdb7/8ddQOniKGaONHy5IpGKhi2mooEWWYatl2i8921lKs7jcg+XKadvA2tazGXrtugJlJCeS2E5g7WjQ2SRtE1ivRdcS1O2HWrnhIdCrc4RBVPzBfP/w25wmEGd0hhm8n4/ruq+8P/P53Lw/tXvx8nN/7ntMDofDIQAAAAMJ8ncBAAAAvY0ABAAADIcABAAADIcABAAADIcABAAADIcABAAADIcABAAADIcABAAADOdSfxcQiDo7O/X1118rJCREJpPJ3+UAAAA3OBwOtbW1adCgQQoK6nmNhwDUja+//lrR0dH+LgMAAJyHAwcOKCoqqsc+BKBuhISESDrzL9Bisfi5GgAA4A673a7o6Gjn7/GeEIC68e1tL4vFQgACAKCPcWf7CpugAQCA4RCAAACA4RCAAACA4RCAAACA4RCAAACA4RCAAACA4RCAAACA4RCAAACA4RCAAACA4QRMAMrJyZHJZNLPf/7zHvtVV1frhhtuUHBwsK655hq9/PLLXfrYbDbFx8fLbDYrPj5e69ev91HVAACgLwqIALR9+3YVFhYqISGhx3779+/XtGnTdNNNN6murk7Z2dl6/PHHZbPZnH1qa2s1e/ZspaWlaefOnUpLS9OsWbO0bds2X08DAAD0ESaHw+HwZwFHjhzRmDFj9NJLL+m5557T9ddfr9zc3G77/vKXv1RFRYU+/fRTZ9v8+fO1c+dO1dbWSpJmz54tu92uDRs2OPv8+Mc/1hVXXKHS0lK3arLb7bJarWptbeW7wAAA6CM8+f3t9y9DzcjI0B133KHbbrtNzz33XI99a2trNWXKFJe222+/XUVFRTp58qT69eun2tpaLV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MhwAEAAAMhwAEAAAMhwAEAAAMhwAEAAAMhwAEAAAMhwAEAAAMhwAEAAAMhwAEAAAMhwAEAAAMhwAEAAAMhwAEAAAMhwAEAAAMhwAEAAAMhwAEAAAMx68BqKCgQAkJCbJYLLJYLEpOTtaGDRvO2r+qqkomk6nL8dlnn7n0s9lsio+Pl9lsVnx8vNavX+/rqQAAgD7ErwEoKipKy5Yt04cffqgPP/xQt956q2bMmKGPP/64x3F79uxRU1OT8xg2bJjzs9raWs2ePVtpaWnauXOn0tLSNGvWLG3bts3X0wEAAH3Epf784dOnT3c5X7p0qQoKCrR161aNGDHirOPCwsI0cODAbj/Lzc1VamqqsrKyJElZWVmqrq5Wbm6uSktLvVY7AADouwJmD9Dp06dVVlam9vZ2JScn99h39OjRioyM1OTJk7V582aXz2prazVlyhSXtttvv11//etfz3q9jo4O2e12lwMAAFy8/B6Adu/ercsvv1xms1nz58/X+vXrFR8f323fyMhIFRYWymazad26dRo+fLgmT56smpoaZ5/m5maFh4e7jAsPD1dzc/NZa8jJyZHVanUe0dHR3pkcAAAISH69BSZJw4cPV319vVpaWmSz2fTQQw+purq62xA0fPhwDR8+3HmenJysAwcO6He/+51SUlKc7SaTyWWcw+Ho0vZdWVlZyszMdJ7b7XZCEAAAFzG/B6D+/ftr6NChkqTExERt375deXl5Wr16tVvjk5KS9PrrrzvPIyIiuqz2HDp0qMuq0HeZzWaZzebzqB4AAPRFfr8F9n0Oh0MdHR1u96+rq1NkZKTzPDk5WZs2bXLps3HjRk2YMMFrNQIAgL7Nryt
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Boxplot for sepal width (cm) after outlier treatment\n",
"sns.boxplot(y=df['sepal width (cm)'])\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "4e7a2ded-1e62-479f-82c9-2fe73e2af3b7",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split\n",
"\n",
"# Splitting the data into train and test sets\n",
"X = df.drop(\"Species\",axis=1)\n",
"y = df[\"Species\"]\n",
"X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3, random_state= 1)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "139a1941-1c75-4ead-81ed-83031c9f3ad6",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-1 {\n",
" /* Definition of color scheme common for light and dark mode */\n",
" --sklearn-color-text: black;\n",
" --sklearn-color-line: gray;\n",
" /* Definition of color scheme for unfitted estimators */\n",
" --sklearn-color-unfitted-level-0: #fff5e6;\n",
" --sklearn-color-unfitted-level-1: #f6e4d2;\n",
" --sklearn-color-unfitted-level-2: #ffe0b3;\n",
" --sklearn-color-unfitted-level-3: chocolate;\n",
" /* Definition of color scheme for fitted estimators */\n",
" --sklearn-color-fitted-level-0: #f0f8ff;\n",
" --sklearn-color-fitted-level-1: #d4ebff;\n",
" --sklearn-color-fitted-level-2: #b3dbfd;\n",
" --sklearn-color-fitted-level-3: cornflowerblue;\n",
"\n",
" /* Specific color for light theme */\n",
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
" --sklearn-color-icon: #696969;\n",
"\n",
" @media (prefers-color-scheme: dark) {\n",
" /* Redefinition of color scheme for dark theme */\n",
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
" --sklearn-color-icon: #878787;\n",
" }\n",
"}\n",
"\n",
"#sk-container-id-1 {\n",
" color: var(--sklearn-color-text);\n",
"}\n",
"\n",
"#sk-container-id-1 pre {\n",
" padding: 0;\n",
"}\n",
"\n",
"#sk-container-id-1 input.sk-hidden--visually {\n",
" border: 0;\n",
" clip: rect(1px 1px 1px 1px);\n",
" clip: rect(1px, 1px, 1px, 1px);\n",
" height: 1px;\n",
" margin: -1px;\n",
" overflow: hidden;\n",
" padding: 0;\n",
" position: absolute;\n",
" width: 1px;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-dashed-wrapped {\n",
" border: 1px dashed var(--sklearn-color-line);\n",
" margin: 0 0.4em 0.5em 0.4em;\n",
" box-sizing: border-box;\n",
" padding-bottom: 0.4em;\n",
" background-color: var(--sklearn-color-background);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-container {\n",
" /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
" but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
" so we also need the `!important` here to be able to override the\n",
" default hidden behavior on the sphinx rendered scikit-learn.org.\n",
" See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
" display: inline-block !important;\n",
" position: relative;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-text-repr-fallback {\n",
" display: none;\n",
"}\n",
"\n",
"div.sk-parallel-item,\n",
"div.sk-serial,\n",
"div.sk-item {\n",
" /* draw centered vertical line to link estimators */\n",
" background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
" background-size: 2px 100%;\n",
" background-repeat: no-repeat;\n",
" background-position: center center;\n",
"}\n",
"\n",
"/* Parallel-specific style estimator block */\n",
"\n",
"#sk-container-id-1 div.sk-parallel-item::after {\n",
" content: \"\";\n",
" width: 100%;\n",
" border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
" flex-grow: 1;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-parallel {\n",
" display: flex;\n",
" align-items: stretch;\n",
" justify-content: center;\n",
" background-color: var(--sklearn-color-background);\n",
" position: relative;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-parallel-item {\n",
" display: flex;\n",
" flex-direction: column;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-parallel-item:first-child::after {\n",
" align-self: flex-end;\n",
" width: 50%;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-parallel-item:last-child::after {\n",
" align-self: flex-start;\n",
" width: 50%;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-parallel-item:only-child::after {\n",
" width: 0;\n",
"}\n",
"\n",
"/* Serial-specific style estimator block */\n",
"\n",
"#sk-container-id-1 div.sk-serial {\n",
" display: flex;\n",
" flex-direction: column;\n",
" align-items: center;\n",
" background-color: var(--sklearn-color-background);\n",
" padding-right: 1em;\n",
" padding-left: 1em;\n",
"}\n",
"\n",
"\n",
"/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
"clickable and can be expanded/collapsed.\n",
"- Pipeline and ColumnTransformer use this feature and define the default style\n",
"- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
"*/\n",
"\n",
"/* Pipeline and ColumnTransformer style (default) */\n",
"\n",
"#sk-container-id-1 div.sk-toggleable {\n",
" /* Default theme specific background. It is overwritten whether we have a\n",
" specific estimator or a Pipeline/ColumnTransformer */\n",
" background-color: var(--sklearn-color-background);\n",
"}\n",
"\n",
"/* Toggleable label */\n",
"#sk-container-id-1 label.sk-toggleable__label {\n",
" cursor: pointer;\n",
" display: block;\n",
" width: 100%;\n",
" margin-bottom: 0;\n",
" padding: 0.5em;\n",
" box-sizing: border-box;\n",
" text-align: center;\n",
"}\n",
"\n",
"#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n",
" /* Arrow on the left of the label */\n",
" content: \"▸\";\n",
" float: left;\n",
" margin-right: 0.25em;\n",
" color: var(--sklearn-color-icon);\n",
"}\n",
"\n",
"#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n",
" color: var(--sklearn-color-text);\n",
"}\n",
"\n",
"/* Toggleable content - dropdown */\n",
"\n",
"#sk-container-id-1 div.sk-toggleable__content {\n",
" max-height: 0;\n",
" max-width: 0;\n",
" overflow: hidden;\n",
" text-align: left;\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-toggleable__content.fitted {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-toggleable__content pre {\n",
" margin: 0.2em;\n",
" border-radius: 0.25em;\n",
" color: var(--sklearn-color-text);\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-fitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
" /* Expand drop-down */\n",
" max-height: 200px;\n",
" max-width: 100%;\n",
" overflow: auto;\n",
"}\n",
"\n",
"#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
" content: \"▾\";\n",
"}\n",
"\n",
"/* Pipeline/ColumnTransformer-specific style */\n",
"\n",
"#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" color: var(--sklearn-color-text);\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
"\n",
"/* Estimator-specific style */\n",
"\n",
"/* Colorize estimator box */\n",
"#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n",
"#sk-container-id-1 div.sk-label label {\n",
" /* The background is the default theme color */\n",
" color: var(--sklearn-color-text-on-default-background);\n",
"}\n",
"\n",
"/* On hover, darken the color of the background */\n",
"#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n",
" color: var(--sklearn-color-text);\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"/* Label box, darken color on hover, fitted */\n",
"#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
" color: var(--sklearn-color-text);\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
"\n",
"/* Estimator label */\n",
"\n",
"#sk-container-id-1 div.sk-label label {\n",
" font-family: monospace;\n",
" font-weight: bold;\n",
" display: inline-block;\n",
" line-height: 1.2em;\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-label-container {\n",
" text-align: center;\n",
"}\n",
"\n",
"/* Estimator-specific */\n",
"#sk-container-id-1 div.sk-estimator {\n",
" font-family: monospace;\n",
" border: 1px dotted var(--sklearn-color-border-box);\n",
" border-radius: 0.25em;\n",
" box-sizing: border-box;\n",
" margin-bottom: 0.5em;\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-estimator.fitted {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-0);\n",
"}\n",
"\n",
"/* on hover */\n",
"#sk-container-id-1 div.sk-estimator:hover {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-1 div.sk-estimator.fitted:hover {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
"\n",
"/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
"\n",
"/* Common style for \"i\" and \"?\" */\n",
"\n",
".sk-estimator-doc-link,\n",
"a:link.sk-estimator-doc-link,\n",
"a:visited.sk-estimator-doc-link {\n",
" float: right;\n",
" font-size: smaller;\n",
" line-height: 1em;\n",
" font-family: monospace;\n",
" background-color: var(--sklearn-color-background);\n",
" border-radius: 1em;\n",
" height: 1em;\n",
" width: 1em;\n",
" text-decoration: none !important;\n",
" margin-left: 1ex;\n",
" /* unfitted */\n",
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
" color: var(--sklearn-color-unfitted-level-1);\n",
"}\n",
"\n",
".sk-estimator-doc-link.fitted,\n",
"a:link.sk-estimator-doc-link.fitted,\n",
"a:visited.sk-estimator-doc-link.fitted {\n",
" /* fitted */\n",
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
" color: var(--sklearn-color-fitted-level-1);\n",
"}\n",
"\n",
"/* On hover */\n",
"div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
".sk-estimator-doc-link:hover,\n",
"div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
".sk-estimator-doc-link:hover {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-3);\n",
" color: var(--sklearn-color-background);\n",
" text-decoration: none;\n",
"}\n",
"\n",
"div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
".sk-estimator-doc-link.fitted:hover,\n",
"div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
".sk-estimator-doc-link.fitted:hover {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-3);\n",
" color: var(--sklearn-color-background);\n",
" text-decoration: none;\n",
"}\n",
"\n",
"/* Span, style for the box shown on hovering the info icon */\n",
".sk-estimator-doc-link span {\n",
" display: none;\n",
" z-index: 9999;\n",
" position: relative;\n",
" font-weight: normal;\n",
" right: .2ex;\n",
" padding: .5ex;\n",
" margin: .5ex;\n",
" width: min-content;\n",
" min-width: 20ex;\n",
" max-width: 50ex;\n",
" color: var(--sklearn-color-text);\n",
" box-shadow: 2pt 2pt 4pt #999;\n",
" /* unfitted */\n",
" background: var(--sklearn-color-unfitted-level-0);\n",
" border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
"}\n",
"\n",
".sk-estimator-doc-link.fitted span {\n",
" /* fitted */\n",
" background: var(--sklearn-color-fitted-level-0);\n",
" border: var(--sklearn-color-fitted-level-3);\n",
"}\n",
"\n",
".sk-estimator-doc-link:hover span {\n",
" display: block;\n",
"}\n",
"\n",
"/* \"?\"-specific style due to the `<a>` HTML tag */\n",
"\n",
"#sk-container-id-1 a.estimator_doc_link {\n",
" float: right;\n",
" font-size: 1rem;\n",
" line-height: 1em;\n",
" font-family: monospace;\n",
" background-color: var(--sklearn-color-background);\n",
" border-radius: 1rem;\n",
" height: 1rem;\n",
" width: 1rem;\n",
" text-decoration: none;\n",
" /* unfitted */\n",
" color: var(--sklearn-color-unfitted-level-1);\n",
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
"}\n",
"\n",
"#sk-container-id-1 a.estimator_doc_link.fitted {\n",
" /* fitted */\n",
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
" color: var(--sklearn-color-fitted-level-1);\n",
"}\n",
"\n",
"/* On hover */\n",
"#sk-container-id-1 a.estimator_doc_link:hover {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-3);\n",
" color: var(--sklearn-color-background);\n",
" text-decoration: none;\n",
"}\n",
"\n",
"#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-3);\n",
"}\n",
"</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>DecisionTreeClassifier(max_depth=3, min_samples_leaf=10, random_state=1)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow fitted\">&nbsp;&nbsp;DecisionTreeClassifier<a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.4/modules/generated/sklearn.tree.DecisionTreeClassifier.html\">?<span>Documentation for DecisionTreeClassifier</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></label><div class=\"sk-toggleable__content fitted\"><pre>DecisionTreeClassifier(max_depth=3, min_samples_leaf=10, random_state=1)</pre></div> </div></div></div></div>"
],
"text/plain": [
"DecisionTreeClassifier(max_depth=3, min_samples_leaf=10, random_state=1)"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from sklearn.tree import DecisionTreeClassifier\n",
"\n",
"# Defining an object for DTC and fitting for whole dataset\n",
"dt = DecisionTreeClassifier(max_depth=3, min_samples_leaf=10, random_state=1 )\n",
"dt.fit(X, y)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "9c6be7f6-ae65-4685-be32-5f945f53e869",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAgMAAAGFCAYAAABg2vAPAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8g+/7EAAAACXBIWXMAAA9hAAAPYQGoP6dpAABsqElEQVR4nO3dd1hU1/bw8S9FVLCh3FxbYkVFsCAokToSiYot9h41mpt4Y6yxXGN+YmKLikYTWxTFhg1zY4nGhmOPUsSColERjTEmoBIBURjO+wcvc0VAEYEzMOvzPHnizGlrzp59WLPPPnubKIqiIIQQQgijZap2AEIIIYRQlyQDQgghhJGTZEAIIYQwcpIMCCGEEEZOkgEhhBDCyEkyIIQQQhg5SQaEEEIIIy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F2CEIIUWJJB0JhNLRaLSNHjiz044wcOZLq1avneKz169dTvnx5/WsZmVAIYQgkGRCigE2ZMoWNGzdme//p06cEBwdnmd44c2TCQ4cOcezYMf7xj38UZahCCAFIMiAMSExMDO7u7rRp04aOHTsCEBQUhLe3Ny1btmTq1KlAxi98Hx8f3nvvPezs7NixYwedOnXCwcFB/wiivb0948ePx9PTk2HDhvF8P9mQkBA8PT3x8PBg+vTpAOzevRsXFxc0Go3+WPlRvXr1HB91XLFiBUOGDMkyZoGMTCiEMASSDAiDcfjwYbp3787hw4fZtWsXkPFYYUhICGfOnOHw4cPcvXsXgOTkZP773/8
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from sklearn import tree\n",
"\n",
"#print(dt.feature_names_in_)\n",
"\n",
"t = tree.plot_tree(decision_tree = dt, feature_names=dt.feature_names_in_) # returns a array with each leaf and their values"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "80282a49-1d47-4146-afd8-a9aa359e9791",
"metadata": {},
"outputs": [],
"source": [
"# Defining an object for DTC and fitting for train dataset\n",
"dt = DecisionTreeClassifier(random_state=1)\n",
"dt.fit(X_train, y_train)\n",
"\n",
"y_pred_train = dt.predict(X_train)\n",
"y_pred = dt.predict(X_test)\n",
"y_prob = dt.predict_proba(X_test)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "af602439-ec2e-4ef7-88eb-6d3684fd70ee",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy of Decision Tree-Train: 1.0\n",
"Accuracy of Decision Tree-Test: 0.9545454545454546\n"
]
}
],
"source": [
"from sklearn.metrics import accuracy_score\n",
"\n",
"print('Accuracy of Decision Tree-Train: ', accuracy_score(y_pred_train, y_train))\n",
"print('Accuracy of Decision Tree-Test: ', accuracy_score(y_pred, y_test))"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "0ae9915b-5145-4ffe-a49f-18d44064dfa5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" precision recall f1-score support\n",
"\n",
" Iris-setosa 1.00 1.00 1.00 15\n",
"Iris-versicolor 1.00 0.87 0.93 15\n",
" Iris-virginica 0.88 1.00 0.93 14\n",
"\n",
" accuracy 0.95 44\n",
" macro avg 0.96 0.96 0.95 44\n",
" weighted avg 0.96 0.95 0.95 44\n",
"\n"
]
}
],
"source": [
"from sklearn.metrics import classification_report \n",
"#Classification for test before hyperparameter tuning\n",
"print(classification_report(y_test,y_pred))"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "6906db27-13f0-4e27-b08c-924a303e61ec",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'max_depth': 3, 'min_samples_leaf': 3, 'min_samples_split': 2}"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from sklearn.model_selection import GridSearchCV\n",
"\n",
"\n",
"# Hyperparameter Tuning of DTC\n",
"\n",
"dt = DecisionTreeClassifier(random_state=1)\n",
"\n",
"params = {'max_depth' : [2,3,4,5],\n",
" 'min_samples_split': [2,3,4,5],\n",
" 'min_samples_leaf': [1,2,3,4,5]}\n",
"\n",
"gsearch = GridSearchCV(dt, param_grid=params, cv=3)\n",
"\n",
"gsearch.fit(X,y)\n",
"\n",
"gsearch.best_params_"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "56a75b7b-2915-47e7-9f8b-1f12c72c2196",
"metadata": {},
"outputs": [],
"source": [
"# Passing best parameter for the Hyperparameter Tuning\n",
"dt = DecisionTreeClassifier(**gsearch.best_params_, random_state=1)\n",
"\n",
"dt.fit(X_train, y_train)\n",
"\n",
"y_pred_train = dt.predict(X_train)\n",
"y_prob_train = dt.predict_proba(X_train)[:,1]\n",
"\n",
"y_pred = dt.predict(X_test)\n",
"y_prob = dt.predict_proba(X_test)[:,1]"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "59d0f61b-c0c7-4746-9706-2b0816dca073",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[Text(0.4, 0.875, 'petal width (cm) <= 0.75\\ngini = 0.666\\nsamples = 102\\nvalue = [32, 34, 36]'),\n",
" Text(0.2, 0.625, 'gini = 0.0\\nsamples = 32\\nvalue = [32, 0, 0]'),\n",
" Text(0.6, 0.625, 'petal width (cm) <= 1.65\\ngini = 0.5\\nsamples = 70\\nvalue = [0, 34, 36]'),\n",
" Text(0.4, 0.375, 'petal length (cm) <= 4.95\\ngini = 0.149\\nsamples = 37\\nvalue = [0, 34, 3]'),\n",
" Text(0.2, 0.125, 'gini = 0.0\\nsamples = 33\\nvalue = [0, 33, 0]'),\n",
" Text(0.6, 0.125, 'gini = 0.375\\nsamples = 4\\nvalue = [0, 1, 3]'),\n",
" Text(0.8, 0.375, 'gini = 0.0\\nsamples = 33\\nvalue = [0, 0, 33]')]"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAgMAAAGFCAYAAABg2vAPAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8g+/7EAAAACXBIWXMAAA9hAAAPYQGoP6dpAACM20lEQVR4nOzdd1RU19oH4N8gMAwdRQVRKYI0W+SiIhhEFETFBDEWLIANVLAEo2IDsRcEewdELCREQ9AECyjWa0GwgcpVEL0BIxYiXZj9/eHHuY7S21DeZ61ZK7Nnl3cmc/Cdc87em8cYYyCEEEJIiyUh7gAIIYQQIl6UDBBCCCEtHCUDhBBCSAtHyQAhhBDSwlEyQAghhLRwlAwQQgghLRwlA4QQQkgLR8kAIYQQ0sJRMkAIIYS0cJQMEEIIIS0cJQOEEEJIC0fJACGEENLCUTJACCGEtHCUDBBCCCEtHCUDhBBCSAtHyQAhhBDSwlEyQAghhLRwkuIOgNROeno6srKyxB0GIWKjqqqKzp07izsMQpo0SgaasPT0dBgaGiI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Bhg8fDnd3d+zfvx/S0tKYPXs2zMzMYGFhwdWztrZGnz59sG7dOpH2+/btg7W1NXR0dL7qe+XKlejbty/09PSQk5OD/fv3IzY2FqdPn65xvISQqqHLBM3cuHHjICUlBTMzM0yYMAGjRo0SmULn5+eHtWvXYtu2bejWrRusrKwQHBws8sd68+bNuHPnDrS1tblT1suWLYOFhQXs7e3Rv39/5ObmYvbs2dWOT0dHB5qamtDQ0IC2tjY
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"tree.plot_tree(decision_tree = dt, feature_names=dt.feature_names_in_)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "eb0b0037-7305-4085-a668-92882fec7302",
"metadata": {},
"outputs": [],
"source": [
"# Passing best parameter for the Hyperparameter Tuning\n",
"dt = DecisionTreeClassifier(**gsearch.best_params_, random_state=1)\n",
"\n",
"dt.fit(X_train, y_train)\n",
"\n",
"y_pred_train = dt.predict(X_train)\n",
"y_prob_train = dt.predict_proba(X_train)[:,1]\n",
"\n",
"y_pred = dt.predict(X_test)\n",
"y_prob = dt.predict_proba(X_test)[:,1]"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "d191383c-ba55-43c8-97bb-88816b9763d4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Confusion Matrix - Train: \n",
" [[32 0 0]\n",
" [ 0 33 1]\n",
" [ 0 0 36]]\n",
"\n",
" Confusion Matrix - Test: \n",
" [[15 0 0]\n",
" [ 0 13 2]\n",
" [ 0 0 14]]\n"
]
}
],
"source": [
"from sklearn.metrics import confusion_matrix \n",
"\n",
"print('Confusion Matrix - Train:','\\n',confusion_matrix(y_train,y_pred_train))\n",
"print('\\n','Confusion Matrix - Test:','\\n',confusion_matrix(y_test,y_pred))"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "2e5cdce5-ada0-493e-aefa-e3415abb1d54",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" precision recall f1-score support\n",
"\n",
" Iris-setosa 1.00 1.00 1.00 15\n",
"Iris-versicolor 1.00 0.87 0.93 15\n",
" Iris-virginica 0.88 1.00 0.93 14\n",
"\n",
" accuracy 0.95 44\n",
" macro avg 0.96 0.96 0.95 44\n",
" weighted avg 0.96 0.95 0.95 44\n",
"\n"
]
}
],
"source": [
"#Classification for test after hyperparameter tuning\n",
"print(classification_report(y_test,y_pred))"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "55c4bb77-7646-4c0e-b2e2-24ae9e23e1db",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy of Decision Tree-Train: 0.9901960784313726\n",
"Accuracy of Decision Tree-Test: 0.9545454545454546\n"
]
}
],
"source": [
"print('Accuracy of Decision Tree-Train: ', accuracy_score(y_pred_train, y_train))\n",
"print('Accuracy of Decision Tree-Test: ', accuracy_score(y_pred, y_test))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}