You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2265 lines
1.1 MiB

2 years ago
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"<a href='https://www.udemy.com/user/joseportilla/'><img src='../Pierian_Data_Logo.png'/></a>\n",
"___\n",
"<center><em>Copyright by Pierian Data Inc.</em></center>\n",
"<center><em>For more information, visit us at <a href='http://www.pieriandata.com'>www.pieriandata.com</a></em></center>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Decision Trees"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The Data\n",
"\n",
"We will be using the same dataset through our discussions on classification with tree-methods (Decision Tree,Random Forests, and Gradient Boosted Trees) in order to compare performance metrics across these related models.\n",
"\n",
"We will work with the \"Palmer Penguins\" dataset, as it is simple enough to help us fully understand how changing hyperparameters can change classification results.\n",
"\n",
"\n",
"<img src=\"penguin.jpg\" style=\"max-width:400px\">\n",
"\n",
"Data were collected and made available by Dr. Kristen Gorman and the Palmer Station, Antarctica LTER, a member of the Long Term Ecological Research Network.\n",
"\n",
"Gorman KB, Williams TD, Fraser WR (2014) Ecological Sexual Dimorphism and Environmental Variability within a Community of Antarctic Penguins (Genus Pygoscelis). PLoS ONE 9(3): e90081. doi:10.1371/journal.pone.0090081\n",
"\n",
"Summary:\n",
"The data folder contains two CSV files. For intro courses/examples, you probably want to use the first one (penguins_size.csv).\n",
"\n",
"* penguins_size.csv: Simplified data from original penguin data sets. Contains variables:\n",
"\n",
" * species: penguin species (Chinstrap, Adélie, or Gentoo)\n",
" * culmen_length_mm: culmen length (mm)\n",
" * culmen_depth_mm: culmen depth (mm)\n",
" * flipper_length_mm: flipper length (mm)\n",
" * body_mass_g: body mass (g)\n",
" * island: island name (Dream, Torgersen, or Biscoe) in the Palmer Archipelago (Antarctica)\n",
" * sex: penguin sex\n",
"\n",
"* (Not used) penguins_lter.csv: Original combined data for 3 penguin species \n",
"\n",
"Note: The culmen is \"the upper ridge of a bird's beak\" \n",
"\n",
"**Our goal is to create a model that can help predict a species of a penguin based on physical attributes, then we can use that model to help researchers classify penguins in the field, instead of needing an experienced biologist**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Imports"
]
},
{
"cell_type": "code",
"execution_count": 113,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns"
]
},
{
"cell_type": "code",
"execution_count": 114,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(\"../DATA/penguins_size.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 115,
"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>species</th>\n",
" <th>island</th>\n",
" <th>culmen_length_mm</th>\n",
" <th>culmen_depth_mm</th>\n",
" <th>flipper_length_mm</th>\n",
" <th>body_mass_g</th>\n",
" <th>sex</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Adelie</td>\n",
" <td>Torgersen</td>\n",
" <td>39.1</td>\n",
" <td>18.7</td>\n",
" <td>181.0</td>\n",
" <td>3750.0</td>\n",
" <td>MALE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Adelie</td>\n",
" <td>Torgersen</td>\n",
" <td>39.5</td>\n",
" <td>17.4</td>\n",
" <td>186.0</td>\n",
" <td>3800.0</td>\n",
" <td>FEMALE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Adelie</td>\n",
" <td>Torgersen</td>\n",
" <td>40.3</td>\n",
" <td>18.0</td>\n",
" <td>195.0</td>\n",
" <td>3250.0</td>\n",
" <td>FEMALE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Adelie</td>\n",
" <td>Torgersen</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Adelie</td>\n",
" <td>Torgersen</td>\n",
" <td>36.7</td>\n",
" <td>19.3</td>\n",
" <td>193.0</td>\n",
" <td>3450.0</td>\n",
" <td>FEMALE</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" species island culmen_length_mm culmen_depth_mm flipper_length_mm \\\n",
"0 Adelie Torgersen 39.1 18.7 181.0 \n",
"1 Adelie Torgersen 39.5 17.4 186.0 \n",
"2 Adelie Torgersen 40.3 18.0 195.0 \n",
"3 Adelie Torgersen NaN NaN NaN \n",
"4 Adelie Torgersen 36.7 19.3 193.0 \n",
"\n",
" body_mass_g sex \n",
"0 3750.0 MALE \n",
"1 3800.0 FEMALE \n",
"2 3250.0 FEMALE \n",
"3 NaN NaN \n",
"4 3450.0 FEMALE "
]
},
"execution_count": 115,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## EDA\n",
"\n",
"### Missing Data\n",
"\n",
"Recall the purpose is to create a model for future use, so data points missing crucial information won't help in this task, especially since for future data points we will assume the research will grab the relevant feature information."
]
},
{
"cell_type": "code",
"execution_count": 116,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 344 entries, 0 to 343\n",
"Data columns (total 7 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 species 344 non-null object \n",
" 1 island 344 non-null object \n",
" 2 culmen_length_mm 342 non-null float64\n",
" 3 culmen_depth_mm 342 non-null float64\n",
" 4 flipper_length_mm 342 non-null float64\n",
" 5 body_mass_g 342 non-null float64\n",
" 6 sex 334 non-null object \n",
"dtypes: float64(4), object(3)\n",
"memory usage: 18.9+ KB\n"
]
}
],
"source": [
"df.info()"
]
},
{
"cell_type": "code",
"execution_count": 117,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"species 0\n",
"island 0\n",
"culmen_length_mm 2\n",
"culmen_depth_mm 2\n",
"flipper_length_mm 2\n",
"body_mass_g 2\n",
"sex 10\n",
"dtype: int64"
]
},
"execution_count": 117,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.isna().sum()"
]
},
{
"cell_type": "code",
"execution_count": 118,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.9069767441860463"
]
},
"execution_count": 118,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# What percentage are we dropping?\n",
"100*(10/344)"
]
},
{
"cell_type": "code",
"execution_count": 119,
"metadata": {},
"outputs": [],
"source": [
"df = df.dropna()"
]
},
{
"cell_type": "code",
"execution_count": 120,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"Int64Index: 334 entries, 0 to 343\n",
"Data columns (total 7 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 species 334 non-null object \n",
" 1 island 334 non-null object \n",
" 2 culmen_length_mm 334 non-null float64\n",
" 3 culmen_depth_mm 334 non-null float64\n",
" 4 flipper_length_mm 334 non-null float64\n",
" 5 body_mass_g 334 non-null float64\n",
" 6 sex 334 non-null object \n",
"dtypes: float64(4), object(3)\n",
"memory usage: 20.9+ KB\n"
]
}
],
"source": [
"df.info()"
]
},
{
"cell_type": "code",
"execution_count": 121,
"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>species</th>\n",
" <th>island</th>\n",
" <th>culmen_length_mm</th>\n",
" <th>culmen_depth_mm</th>\n",
" <th>flipper_length_mm</th>\n",
" <th>body_mass_g</th>\n",
" <th>sex</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Adelie</td>\n",
" <td>Torgersen</td>\n",
" <td>39.1</td>\n",
" <td>18.7</td>\n",
" <td>181.0</td>\n",
" <td>3750.0</td>\n",
" <td>MALE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Adelie</td>\n",
" <td>Torgersen</td>\n",
" <td>39.5</td>\n",
" <td>17.4</td>\n",
" <td>186.0</td>\n",
" <td>3800.0</td>\n",
" <td>FEMALE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Adelie</td>\n",
" <td>Torgersen</td>\n",
" <td>40.3</td>\n",
" <td>18.0</td>\n",
" <td>195.0</td>\n",
" <td>3250.0</td>\n",
" <td>FEMALE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Adelie</td>\n",
" <td>Torgersen</td>\n",
" <td>36.7</td>\n",
" <td>19.3</td>\n",
" <td>193.0</td>\n",
" <td>3450.0</td>\n",
" <td>FEMALE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Adelie</td>\n",
" <td>Torgersen</td>\n",
" <td>39.3</td>\n",
" <td>20.6</td>\n",
" <td>190.0</td>\n",
" <td>3650.0</td>\n",
" <td>MALE</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" species island culmen_length_mm culmen_depth_mm flipper_length_mm \\\n",
"0 Adelie Torgersen 39.1 18.7 181.0 \n",
"1 Adelie Torgersen 39.5 17.4 186.0 \n",
"2 Adelie Torgersen 40.3 18.0 195.0 \n",
"4 Adelie Torgersen 36.7 19.3 193.0 \n",
"5 Adelie Torgersen 39.3 20.6 190.0 \n",
"\n",
" body_mass_g sex \n",
"0 3750.0 MALE \n",
"1 3800.0 FEMALE \n",
"2 3250.0 FEMALE \n",
"4 3450.0 FEMALE \n",
"5 3650.0 MALE "
]
},
"execution_count": 121,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 122,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['MALE', 'FEMALE', '.'], dtype=object)"
]
},
"execution_count": 122,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['sex'].unique()"
]
},
{
"cell_type": "code",
"execution_count": 123,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['Torgersen', 'Biscoe', 'Dream'], dtype=object)"
]
},
"execution_count": 123,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['island'].unique()"
]
},
{
"cell_type": "code",
"execution_count": 124,
"metadata": {},
"outputs": [],
"source": [
"df = df[df['sex']!='.']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Visualization"
]
},
{
"cell_type": "code",
"execution_count": 125,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<AxesSubplot:xlabel='culmen_length_mm', ylabel='culmen_depth_mm'>"
]
},
"execution_count": 125,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX8AAAEHCAYAAABGNUbLAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIWXMAAAsTAAALEwEAmpwYAAClL0lEQVR4nOydd3hUZdq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WOwoGqCAPvZiL7b2KgxXbcm0vKJ0ezEjH+M0yIQlChy2dhUfIRDtjIqvdFSDMdQiAqu7DyQ4SkdABAFgeu7DTtrmrInaPX8b/w1WNWh+EScRs//xl3T6tt1Nhe67uMxDpoVfm0YNBN9jwktuKIYjSFW5BXjtNhbWcSl817D5vMAcHP3ETzUf9JJ2z6We5w4Az4UgoBRpcGsbv3B3mP4JYlyrxN3wIdOqSZeYzivpaUlRzlBbyjmIWqMKIwxrZ3WRou0cRQEIQN4H0gFgsAbsiz/WxCEeGAukAUcAq6UZbmiOddyvhGUg5R5nMhyKCisU6qwed14JD9KURERGJZlmVKPA1kGo0qNvoGpopVeF0+t+S5s+AHmZK/i5h4jo4x/ldeNVwqgFEXitQbiOTt3yyqF4pxo1VkTyVGOHPAiKDWNNt4KY3yjzpGDQSR7Ccgyos4ck2RuQZo71TMAPCzL8iZBEEzARkEQfgZuBBbLsvwPQRCeAJ4AHm/mtZw3OP1eVhfm8Mc131PhdXJ7zzFc0Xkgv1v9Db8W7KdHXBv+NfoKOloS8UoBNpfk8sSqryl02ZjZsT+P9J/cIHkInySRay+PGi/zOMgyH0/3K3BW8fiqr1hZcICe8W14cfSVtDcnnNFmMDF
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"sns.scatterplot(x='culmen_length_mm',y='culmen_depth_mm',data=df,hue='species',palette='Dark2')"
]
},
{
"cell_type": "code",
"execution_count": 126,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<seaborn.axisgrid.PairGrid at 0x24fa25bc9c8>"
]
},
"execution_count": 126,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAzIAAALaCAYAAADqVWZ2AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIW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XW2Q/zz+CbFYIus5Qt8ux16+H4rN2XJ8/6SsdHjjp90yTpPdk3hc1SczDZ8vRDzR85Nxwl9Fxb/OIF6TVPeL12yk4l9nkPCbohYm3UNftrG+dC+atE9ftqX2MG3NpLP0SUdGCPGjEOILIcRnQojVza/dLITY2vzaZ0KIk3t7nJ3lo8ofOMBbjmUHwrulLg+bAzvuyASDUepqg5SVGUtADxxUyJFH78n6r6r59z/eZ8UHP1KxtQEpW3JVZTxG5IfV2AcOTztWc2QiGz/b4XGa7L5YrQperyvtNa/XhdXS848tGYvoiwKNeM1GZCza42Mx2TXpyzbWl+5Fk/bpy7bUHqatmXSWvmwZx0gpD5FSjkl57Z/Nrx0ipVzcayPrAnXhJn5orGF/b/8dOk+pK5/KYCMxNXuUpCNs3dyQPF8WRwZg+EH9OWny/kSiCRYt/JI7b3+fv/35XTZ8l6zRiW77ChmPYB9wQNpxFlchloL+RDaZERmTFjpbwOn2OLj4skP1SU3LlXZ7HD0x3DSEzYG1JF1p0FoyDGGz9/hYTHZN+rKNtb4Xh48oY/acccTjqlmM3Qfpy7bUHu09900hAJPWmMX+PcQnVcndkf2LdsyRKXPlo0pJRVM9w/LbLsRviy2aI1Patnra0GFehgwtorEhTGVlgM8+qeDhB1Yx+6pxFFd8BiSVylpjK9mDyNZ1XR6
"text/plain": [
"<Figure size 804.125x720 with 20 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"sns.pairplot(df,hue='species',palette='Dark2')"
]
},
{
"cell_type": "code",
"execution_count": 127,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/plain": [
"<seaborn.axisgrid.FacetGrid at 0x24fa3019ec8>"
]
},
"execution_count": 127,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAsgAAAFgCAYAAACmDI9oAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6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sQv4KvDJzNwOvKtY+u0m4NnApi7nkLTMbN26lfvuu4+tW7dWHUWS1GdWdLPxzNwDXDDP8Vd1830lLW8zMzNMTk6SmUxOTlKr1ZxmIUlqmcu8SRo4roMsSToRXR1BlqoyMTHB1NRUR9ucnp4GYHR0tKPtAoyNjbFpkzONOmW+dZDf9KY3VZxKktQvHEGWWnTo0CEOHTpUdQy1wHWQJUknwhFkDaRujMZu3LgRgM2bN3e8bXVWrVZjcnIScB1kSVL7HEGWNHBcB1mSdCIcQZY0kGq1Gnv27HH0WJLUNgtkSQNpZGSELVu2VB1DktSHnGIhSZIklVggS5IkSSVOsZBUOdetliT1EgtkSQPJNaslSYtlgSypcq5bLUnqJc5BliRJkkoskCVJkqQSC2RJkiSpxAJZkiRJKrFAliRJkkoskCVJkqQSC2RJkiSpxAJZkiRJKrFAliRJkkoskCVJkqQSC2RJkiSpZEXVAbS8TUxMMDU1VXWMluzevRuAjRs3VpykdWNjY2zatKnqGJIk9RULZFVqamqKb+76Omef3Kg6yoKGDp8EwIHbv1xxktbsvX+46giSJPUlC2RV7uyTG1z++P1Vxxg4V+xZXXUESZL6knOQJUmSpBILZEmSJKnEAlmSJEkqsUCWJEmSSiyQJUnSkpmZmWHDhg3s3+/J2epdFsiSJGnJ1Ot1du3aRb1erzqKdEwWyJIkaUnMzMwwOTlJZjI5OekosnqW6yCrUtPT0xy8f9g1e7tg7/3D3DM9XXU
"text/plain": [
"<Figure size 720x360 with 2 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"sns.catplot(x='species',y='culmen_length_mm',data=df,kind='box',col='sex',palette='Dark2')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Feature Engineering"
]
},
{
"cell_type": "code",
"execution_count": 128,
"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>culmen_length_mm</th>\n",
" <th>culmen_depth_mm</th>\n",
" <th>flipper_length_mm</th>\n",
" <th>body_mass_g</th>\n",
" <th>species_Adelie</th>\n",
" <th>species_Chinstrap</th>\n",
" <th>species_Gentoo</th>\n",
" <th>island_Biscoe</th>\n",
" <th>island_Dream</th>\n",
" <th>island_Torgersen</th>\n",
" <th>sex_FEMALE</th>\n",
" <th>sex_MALE</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>39.1</td>\n",
" <td>18.7</td>\n",
" <td>181.0</td>\n",
" <td>3750.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>39.5</td>\n",
" <td>17.4</td>\n",
" <td>186.0</td>\n",
" <td>3800.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>40.3</td>\n",
" <td>18.0</td>\n",
" <td>195.0</td>\n",
" <td>3250.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>36.7</td>\n",
" <td>19.3</td>\n",
" <td>193.0</td>\n",
" <td>3450.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>39.3</td>\n",
" <td>20.6</td>\n",
" <td>190.0</td>\n",
" <td>3650.0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>338</th>\n",
" <td>47.2</td>\n",
" <td>13.7</td>\n",
" <td>214.0</td>\n",
" <td>4925.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>340</th>\n",
" <td>46.8</td>\n",
" <td>14.3</td>\n",
" <td>215.0</td>\n",
" <td>4850.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>341</th>\n",
" <td>50.4</td>\n",
" <td>15.7</td>\n",
" <td>222.0</td>\n",
" <td>5750.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>342</th>\n",
" <td>45.2</td>\n",
" <td>14.8</td>\n",
" <td>212.0</td>\n",
" <td>5200.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>343</th>\n",
" <td>49.9</td>\n",
" <td>16.1</td>\n",
" <td>213.0</td>\n",
" <td>5400.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>333 rows × 12 columns</p>\n",
"</div>"
],
"text/plain": [
" culmen_length_mm culmen_depth_mm flipper_length_mm body_mass_g \\\n",
"0 39.1 18.7 181.0 3750.0 \n",
"1 39.5 17.4 186.0 3800.0 \n",
"2 40.3 18.0 195.0 3250.0 \n",
"4 36.7 19.3 193.0 3450.0 \n",
"5 39.3 20.6 190.0 3650.0 \n",
".. ... ... ... ... \n",
"338 47.2 13.7 214.0 4925.0 \n",
"340 46.8 14.3 215.0 4850.0 \n",
"341 50.4 15.7 222.0 5750.0 \n",
"342 45.2 14.8 212.0 5200.0 \n",
"343 49.9 16.1 213.0 5400.0 \n",
"\n",
" species_Adelie species_Chinstrap species_Gentoo island_Biscoe \\\n",
"0 1 0 0 0 \n",
"1 1 0 0 0 \n",
"2 1 0 0 0 \n",
"4 1 0 0 0 \n",
"5 1 0 0 0 \n",
".. ... ... ... ... \n",
"338 0 0 1 1 \n",
"340 0 0 1 1 \n",
"341 0 0 1 1 \n",
"342 0 0 1 1 \n",
"343 0 0 1 1 \n",
"\n",
" island_Dream island_Torgersen sex_FEMALE sex_MALE \n",
"0 0 1 0 1 \n",
"1 0 1 1 0 \n",
"2 0 1 1 0 \n",
"4 0 1 1 0 \n",
"5 0 1 0 1 \n",
".. ... ... ... ... \n",
"338 0 0 1 0 \n",
"340 0 0 1 0 \n",
"341 0 0 0 1 \n",
"342 0 0 1 0 \n",
"343 0 0 0 1 \n",
"\n",
"[333 rows x 12 columns]"
]
},
"execution_count": 128,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.get_dummies(df)"
]
},
{
"cell_type": "code",
"execution_count": 130,
"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>culmen_length_mm</th>\n",
" <th>culmen_depth_mm</th>\n",
" <th>flipper_length_mm</th>\n",
" <th>body_mass_g</th>\n",
" <th>island_Dream</th>\n",
" <th>island_Torgersen</th>\n",
" <th>sex_MALE</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>39.1</td>\n",
" <td>18.7</td>\n",
" <td>181.0</td>\n",
" <td>3750.0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>39.5</td>\n",
" <td>17.4</td>\n",
" <td>186.0</td>\n",
" <td>3800.0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>40.3</td>\n",
" <td>18.0</td>\n",
" <td>195.0</td>\n",
" <td>3250.0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>36.7</td>\n",
" <td>19.3</td>\n",
" <td>193.0</td>\n",
" <td>3450.0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>39.3</td>\n",
" <td>20.6</td>\n",
" <td>190.0</td>\n",
" <td>3650.0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>338</th>\n",
" <td>47.2</td>\n",
" <td>13.7</td>\n",
" <td>214.0</td>\n",
" <td>4925.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>340</th>\n",
" <td>46.8</td>\n",
" <td>14.3</td>\n",
" <td>215.0</td>\n",
" <td>4850.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>341</th>\n",
" <td>50.4</td>\n",
" <td>15.7</td>\n",
" <td>222.0</td>\n",
" <td>5750.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>342</th>\n",
" <td>45.2</td>\n",
" <td>14.8</td>\n",
" <td>212.0</td>\n",
" <td>5200.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>343</th>\n",
" <td>49.9</td>\n",
" <td>16.1</td>\n",
" <td>213.0</td>\n",
" <td>5400.0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>333 rows × 7 columns</p>\n",
"</div>"
],
"text/plain": [
" culmen_length_mm culmen_depth_mm flipper_length_mm body_mass_g \\\n",
"0 39.1 18.7 181.0 3750.0 \n",
"1 39.5 17.4 186.0 3800.0 \n",
"2 40.3 18.0 195.0 3250.0 \n",
"4 36.7 19.3 193.0 3450.0 \n",
"5 39.3 20.6 190.0 3650.0 \n",
".. ... ... ... ... \n",
"338 47.2 13.7 214.0 4925.0 \n",
"340 46.8 14.3 215.0 4850.0 \n",
"341 50.4 15.7 222.0 5750.0 \n",
"342 45.2 14.8 212.0 5200.0 \n",
"343 49.9 16.1 213.0 5400.0 \n",
"\n",
" island_Dream island_Torgersen sex_MALE \n",
"0 0 1 1 \n",
"1 0 1 0 \n",
"2 0 1 0 \n",
"4 0 1 0 \n",
"5 0 1 1 \n",
".. ... ... ... \n",
"338 0 0 0 \n",
"340 0 0 0 \n",
"341 0 0 1 \n",
"342 0 0 0 \n",
"343 0 0 1 \n",
"\n",
"[333 rows x 7 columns]"
]
},
"execution_count": 130,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.get_dummies(df.drop('species',axis=1),drop_first=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Train | Test Split"
]
},
{
"cell_type": "code",
"execution_count": 131,
"metadata": {},
"outputs": [],
"source": [
"X = pd.get_dummies(df.drop('species',axis=1),drop_first=True)\n",
"y = df['species']"
]
},
{
"cell_type": "code",
"execution_count": 132,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split"
]
},
{
"cell_type": "code",
"execution_count": 133,
"metadata": {},
"outputs": [],
"source": [
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=101)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Decision Tree Classifier\n",
"\n",
"## Default Hyperparameters"
]
},
{
"cell_type": "code",
"execution_count": 137,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.tree import DecisionTreeClassifier"
]
},
{
"cell_type": "code",
"execution_count": 138,
"metadata": {},
"outputs": [],
"source": [
"model = DecisionTreeClassifier()"
]
},
{
"cell_type": "code",
"execution_count": 140,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DecisionTreeClassifier()"
]
},
"execution_count": 140,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.fit(X_train,y_train)"
]
},
{
"cell_type": "code",
"execution_count": 141,
"metadata": {},
"outputs": [],
"source": [
"base_pred = model.predict(X_test)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Evaluation"
]
},
{
"cell_type": "code",
"execution_count": 157,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.metrics import confusion_matrix,classification_report,plot_confusion_matrix"
]
},
{
"cell_type": "code",
"execution_count": 158,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[38, 2, 0],\n",
" [ 1, 26, 0],\n",
" [ 1, 0, 32]], dtype=int64)"
]
},
"execution_count": 158,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"confusion_matrix(y_test,base_pred)"
]
},
{
"cell_type": "code",
"execution_count": 161,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<sklearn.metrics._plot.confusion_matrix.ConfusionMatrixDisplay at 0x24fa55e2888>"
]
},
"execution_count": 161,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAVwAAAEGCAYAAAApAy29AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIWXMAAAsTAAALEwEAmpwYAAAkTElEQVR4nO3deZxcVZ338c+3O509IYROQhKCCYsggxAwoCzDJCDrjA/gg2IeVHQYAgwM4jai8kIEZWRQEWSbsIzBYZEdRIFEksgyQDYDhM0oBCQJISsBsnR39e/5496GounuqnRXV90uvu/X675y695b5/7qUvz61LnnnKuIwMzMul9NpQMwM/uwcMI1MysTJ1wzszJxwjUzKxMnXDOzMulV6QB6mvqhtTF2TF2lw8isxc8NqnQImRdNuUqHkHlvsXZVRAzrShmHTxoQq9cUvtbzn978YEQc0ZVzFcsJdwuNHVPHnAfHVDqMzDrq4wdXOoTM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gJ18yqVim6hUXEo9DmGOHfb2lZTrhmVrVK1YZbKk64ZlaVAtGcsaG9TrhmVrUyVsF1wjWzKlW6m2Yl44RrZtUrY1VcJ1wzq1o9poYr6Zd08PchIs7slojMzEoggObmHpJwgXlli8LMrNQC6Ck13IiYlv9a0oCIeKf7QzIzK42s9cMt2ElN0n6SngOeT1/vKenKbo/MzKyrooiljIrpFfwL4HBgNUBEPAUc1I0xmZmVQOGJa8p9U62oXgoR8bdkwpx35bonHDOzEspYk0IxCfdvkvYHQlJv4EzS5gUzs8wKiIz1UiimSeFU4HSSZ/gsBca
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plot_confusion_matrix(model,X_test,y_test)"
]
},
{
"cell_type": "code",
"execution_count": 144,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" precision recall f1-score support\n",
"\n",
" Adelie 0.95 0.95 0.95 40\n",
" Chinstrap 0.93 0.96 0.95 27\n",
" Gentoo 1.00 0.97 0.98 33\n",
"\n",
" accuracy 0.96 100\n",
" macro avg 0.96 0.96 0.96 100\n",
"weighted avg 0.96 0.96 0.96 100\n",
"\n"
]
}
],
"source": [
"print(classification_report(y_test,base_pred))"
]
},
{
"cell_type": "code",
"execution_count": 174,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.33350103, 0.02010577, 0.57575804, 0. , 0.04491847,\n",
" 0. , 0.02571668])"
]
},
"execution_count": 174,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.feature_importances_"
]
},
{
"cell_type": "code",
"execution_count": 177,
"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>Feature Importance</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>culmen_length_mm</th>\n",
" <td>0.333501</td>\n",
" </tr>\n",
" <tr>\n",
" <th>culmen_depth_mm</th>\n",
" <td>0.020106</td>\n",
" </tr>\n",
" <tr>\n",
" <th>flipper_length_mm</th>\n",
" <td>0.575758</td>\n",
" </tr>\n",
" <tr>\n",
" <th>body_mass_g</th>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>island_Dream</th>\n",
" <td>0.044918</td>\n",
" </tr>\n",
" <tr>\n",
" <th>island_Torgersen</th>\n",
" <td>0.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>sex_MALE</th>\n",
" <td>0.025717</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Feature Importance\n",
"culmen_length_mm 0.333501\n",
"culmen_depth_mm 0.020106\n",
"flipper_length_mm 0.575758\n",
"body_mass_g 0.000000\n",
"island_Dream 0.044918\n",
"island_Torgersen 0.000000\n",
"sex_MALE 0.025717"
]
},
"execution_count": 177,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.DataFrame(index=X.columns,data=model.feature_importances_,columns=['Feature Importance'])"
]
},
{
"cell_type": "code",
"execution_count": 180,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<AxesSubplot:xlabel='species', ylabel='body_mass_g'>"
]
},
"execution_count": 180,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAAEGCAYAAAB2EqL0AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIWXMAAAsTAAALEwEAmpwYAAAeH0lEQVR4nO3de7i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lf1b9bS0tNDRkQ1S0NDQQEtLywG2MBs4ivRhnJ06vc8jGwxwKtl8GGaW07hx45g7dy6SmDt3Lscee2y9UzLLrUgfxsh0fy7wjYj4TRojyswKaGlpYfPmzW5d9HhikE3R+mS6P7KuWeT3BBWbPahIwbgpzWWxE3inpPHA05VJw2z4GDduHFdffXW90xgQmpqa6p1CYZs2Zdf6TJk4pc6Z5DSxcu9z7oIRER+U9HHg9xGxV9IfyKZUNTM7KIPxarzh3IdYdLTaicBZkkaXxJZWMB8zMxugilwl9f+AM4BpwHeBucBPcMEwMxsWivQ0XUg2h8WvI+JtZJfVjqpKVmZmNuAUKRg7I2IfsEfSWLJ5uMvNsmdmZkNQkT6MTklHAV8A1pJdXLamGkmZmdnAU+QqqXemxc9JugUYGxHrqpOWWf0NxrHAPA6YVVOhX8tIOlXS64GXA02S3pBzuxGS7pZ0c3r8YUm/knRPup1bsu4iSV2SHpB0Tkl8pqT16bk2+VeDNkh5LDAbrIpcJfUl4FRgA7AvhQP4To7N3w38DBhbEvt0RFzV6xjTgPnAKcAJwPclTY2IvcC1wELgdrKrtOYAHXnzNyvKY4GZPVeRPozZETGt6AEkNQKvAxYDBxrH+Xzg+ojYBTwkqQuYJWkz2Smw1WmfS4F
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"sns.boxplot(x='species',y='body_mass_g',data=df)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Visualize the Tree\n",
"\n",
"This function is fairly new, you may want to review the online docs:\n",
"\n",
"Online Documentation: https://scikit-learn.org/stable/modules/generated/sklearn.tree.plot_tree.html"
]
},
{
"cell_type": "code",
"execution_count": 145,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.tree import plot_tree"
]
},
{
"cell_type": "code",
"execution_count": 153,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAqsAAAHBCAYAAABOnPJQA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Am5sbgwYNyna/Ll262P/fsmVLVq1ala/zXLlyheXLl/Pee+/h6+vL/Pnz8/X6OnXqUKeObeanm266iZo1a3L69GkSEhJISUkhKCgIgDvvvJOVK1cSEBDAxx9/zIEDBwBbslujRo0sx125ciU//vgjACNGjODJJ5/koYceyldsSil1PZqsKqVUAVWqVImnn36aMWPGsH///jy9ZvHixdx555152veXX35hwYIFLF++nJ49e/Lqq68SGhoKQHR0NCNHjszymvr16xMREZHjMX/66SdSUlK4+eab2blzJ56envbnPD092bRpEwkJCbi5uTFp0iS2bt1KUFAQb731Fu7u7pmOde7cOapVq2Z/7YkTJ/L0vpRSKj+0G4BSShXCN998w0033cTBgwevu++bb76JiHDHHXdcd9///ve/+Pv7U716daKionj33XftiSpAYGAge/bsybLllqiePn2au+++2367Pru5Z40xJCcnc/jwYfr06cPu3bupU6cOr7zySrb75vazUkoVBU1WlVKqgLZu3cqhQ4f47rvvmDJlCleuXMlx35UrV/Kf//yHJUuW5Cmp69WrF7NmzWLZsmWMGDGCNWvWkJaWZn8+OjqakJCQLFtYWFi2x7t8+TK33XYbTz75JO3atQOytoaeOHGCunXr4uHhgbu7u71bw9ChQ9m7d2+WY7q7u9v70Ga8Vimlipomq0opVQBpaWk88sgjzJkzB39/f/r06cMbb7yR7b67du1i0qRJfPXVV1StWjVPx3d3d+eRRx5hz549TJw4kU8//RRfX197q2h+WlZFhNGjR9O9e/dMXQfq1atH2bJliYqKIjU1laVLlzJo0CCMMfTu3ZsffvgBgI0bN9KsWbMsxx04cCAfffQRAB9//HGOfXaVUqowdLlVpZTLK47lVufPn09kZCSLFi0CICEhgZYtW7JlyxbeffddPDw87IONevbsyb59+6hduzYAnTt3Zs6cOYAtEZw7dy5ffPHFdc955swZ9uzZQ/fu3fMV65YtW+jcubN9IBXAJ598gp+fH9u3b+fee+8lKSmJkSNHMn36dACOHDnCyJEjSUxMpEGDBixevJiaNWvy3HPPERoaSlhYGH/99RdDhw4lPj4ef39/Pv30UypVqpSv2PJCl1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P/88zRu3JgaNWrYB1s999xzREREADBt2jQ+/PBDgoKCePvtt+2j/p988knOnz/PwIEDCQkJ4ZFHHgGgf//+lC9fHn9/f2699VYWLFhAmTL68aGUKhm6KIBSyuWV5KIAFy9epEqVKvz555+0a9eOPXv22EfRq4LRRQGUKt20z6pSShWhe+65h4MHD3LlyhVefvllTVSVUqqQtGVVKeXydLlV56Ytq0qVbtrpSCmlHNT06dMzjdQvbt9++y0tW7YkKCiIDh06sG/fPgBiY2Np0aIFISEhhISE2Pu+JiYm0qpVK0JCQggMDGTBggUlFqtSqvTQbgBKKaUAuPHGG1mzZg21a9fmu+++44EHHmDTpk3cfPPNbN++nfLly/PXX3/RvHlzBg0aROXKldm0aROVK1fm0qVLBAQEMHjwYJ0pQClVpLRlVSml8uHixYv069eP4OBgAgICWLduHQD3338/LVu2xN/fn3feece+v4eHB48//jhNmzZl+PDhrF27lrZt2xIYGEhcXBwAo0ePZsKECfbXZzfl1aFDh+jVqxctW7akd+/e/P777wBMmTKFZs2aERQUxEsvvVSo9xYSEkLt2rWBzMutVqhQgfLlywNw6dIl0tLSANscsZUrVwYgKSmJ1NRU+3NKKVVUNFlVSql8+Prrr7n55pv
"text/plain": [
"<Figure size 864x576 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(12,8))\n",
"plot_tree(model);"
]
},
{
"cell_type": "code",
"execution_count": 166,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABZEAAAOnCAYAAABRRAhMAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIWXMAABcSAAAXEgFnn9JSAAEAAElEQVR4nOzdd3QU1RvG8e8lhXRSSEIghBYg9N6lCoh0BewIKioiSlGxgIggSEdAEfwhIihdUBERlF6k9957b0IS0uf3x4aVFRI6S3k+53COe+fOzDsblc2Tm/cay7IQEREREREREREREbmaDM4uQERERERERERERETuXQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTQqRRURERERERERERCRNCpFFREREREREREREJE0KkUVEREREREREREQkTa7OLkBERERE7i/GGAN4ObsOEQEg1rIsy9lFiIiIyINNIbKIiIiI3CgvINrZRYgIAD5AjLOLEBERkQeb2lmIiIiIiIiIiIiISJq0EllEREREbtrh7evw9lJnC5G7KSY2lmz5izu7DBEREXmIKEQWERERkZvm7eWFt7dCZBERERGRB5naWYiIi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0+78/fc2ZQukQxAN56/RVat+9EYmIibm5u9nM/7Pg2tR+tBsD7HdpSvV4T2r/xqv29/uSDdxg3aSqr1q6nRtVHrnr/xMREZv45l/GTpzFj9l+EZw3jqScaMqBXNwrkz3vVc1YtmHXN58oWluW6nh/g3D//0KlLD5o0rGd/H44es/VHzpLF8T3PEhJMYmIip06fISxLKHv27mfvgYMYDGO++ZL
"text/plain": [
"<Figure size 1800x1200 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(12,8),dpi=150)\n",
"plot_tree(model,filled=True,feature_names=X.columns);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reporting Model Results\n",
"\n",
"To begin experimenting with hyperparameters, let's create a function that reports back classification results and plots out the tree."
]
},
{
"cell_type": "code",
"execution_count": 171,
"metadata": {},
"outputs": [],
"source": [
"def report_model(model):\n",
" model_preds = model.predict(X_test)\n",
" print(classification_report(y_test,model_preds))\n",
" print('\\n')\n",
" plt.figure(figsize=(12,8),dpi=150)\n",
" plot_tree(model,filled=True,feature_names=X.columns);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Understanding Hyperparameters\n",
"\n",
"### Max Depth"
]
},
{
"cell_type": "code",
"execution_count": 168,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Help on class DecisionTreeClassifier in module sklearn.tree._classes:\n",
"\n",
"class DecisionTreeClassifier(sklearn.base.ClassifierMixin, BaseDecisionTree)\n",
" | DecisionTreeClassifier(*, criterion='gini', splitter='best', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None, random_state=None, max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None, class_weight=None, presort='deprecated', ccp_alpha=0.0)\n",
" | \n",
" | A decision tree classifier.\n",
" | \n",
" | Read more in the :ref:`User Guide <tree>`.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | criterion : {\"gini\", \"entropy\"}, default=\"gini\"\n",
" | The function to measure the quality of a split. Supported criteria are\n",
" | \"gini\" for the Gini impurity and \"entropy\" for the information gain.\n",
" | \n",
" | splitter : {\"best\", \"random\"}, default=\"best\"\n",
" | The strategy used to choose the split at each node. Supported\n",
" | strategies are \"best\" to choose the best split and \"random\" to choose\n",
" | the best random split.\n",
" | \n",
" | max_depth : int, default=None\n",
" | The maximum depth of the tree. If None, then nodes are expanded until\n",
" | all leaves are pure or until all leaves contain less than\n",
" | min_samples_split samples.\n",
" | \n",
" | min_samples_split : int or float, default=2\n",
" | The minimum number of samples required to split an internal node:\n",
" | \n",
" | - If int, then consider `min_samples_split` as the minimum number.\n",
" | - If float, then `min_samples_split` is a fraction and\n",
" | `ceil(min_samples_split * n_samples)` are the minimum\n",
" | number of samples for each split.\n",
" | \n",
" | .. versionchanged:: 0.18\n",
" | Added float values for fractions.\n",
" | \n",
" | min_samples_leaf : int or float, default=1\n",
" | The minimum number of samples required to be at a leaf node.\n",
" | A split point at any depth will only be considered if it leaves at\n",
" | least ``min_samples_leaf`` training samples in each of the left and\n",
" | right branches. This may have the effect of smoothing the model,\n",
" | especially in regression.\n",
" | \n",
" | - If int, then consider `min_samples_leaf` as the minimum number.\n",
" | - If float, then `min_samples_leaf` is a fraction and\n",
" | `ceil(min_samples_leaf * n_samples)` are the minimum\n",
" | number of samples for each node.\n",
" | \n",
" | .. versionchanged:: 0.18\n",
" | Added float values for fractions.\n",
" | \n",
" | min_weight_fraction_leaf : float, default=0.0\n",
" | The minimum weighted fraction of the sum total of weights (of all\n",
" | the input samples) required to be at a leaf node. Samples have\n",
" | equal weight when sample_weight is not provided.\n",
" | \n",
" | max_features : int, float or {\"auto\", \"sqrt\", \"log2\"}, default=None\n",
" | The number of features to consider when looking for the best split:\n",
" | \n",
" | - If int, then consider `max_features` features at each split.\n",
" | - If float, then `max_features` is a fraction and\n",
" | `int(max_features * n_features)` features are considered at each\n",
" | split.\n",
" | - If \"auto\", then `max_features=sqrt(n_features)`.\n",
" | - If \"sqrt\", then `max_features=sqrt(n_features)`.\n",
" | - If \"log2\", then `max_features=log2(n_features)`.\n",
" | - If None, then `max_features=n_features`.\n",
" | \n",
" | Note: the search for a split does not stop until at least one\n",
" | valid partition of the node samples is found, even if it requires to\n",
" | effectively inspect more than ``max_features`` features.\n",
" | \n",
" | random_state : int, RandomState instance, default=None\n",
" | Controls the randomness of the estimator. The features are always\n",
" | randomly permuted at each split, even if ``splitter`` is set to\n",
" | ``\"best\"``. When ``max_features < n_features``, the algorithm will\n",
" | select ``max_features`` at random at each split before finding the best\n",
" | split among them. But the best found split may vary across different\n",
" | runs, even if ``max_features=n_features``. That is the case, if the\n",
" | improvement of the criterion is identical for several splits and one\n",
" | split has to be selected at random. To obtain a deterministic behaviour\n",
" | during fitting, ``random_state`` has to be fixed to an integer.\n",
" | See :term:`Glossary <random_state>` for details.\n",
" | \n",
" | max_leaf_nodes : int, default=None\n",
" | Grow a tree with ``max_leaf_nodes`` in best-first fashion.\n",
" | Best nodes are defined as relative reduction in impurity.\n",
" | If None then unlimited number of leaf nodes.\n",
" | \n",
" | min_impurity_decrease : float, default=0.0\n",
" | A node will be split if this split induces a decrease of the impurity\n",
" | greater than or equal to this value.\n",
" | \n",
" | The weighted impurity decrease equation is the following::\n",
" | \n",
" | N_t / N * (impurity - N_t_R / N_t * right_impurity\n",
" | - N_t_L / N_t * left_impurity)\n",
" | \n",
" | where ``N`` is the total number of samples, ``N_t`` is the number of\n",
" | samples at the current node, ``N_t_L`` is the number of samples in the\n",
" | left child, and ``N_t_R`` is the number of samples in the right child.\n",
" | \n",
" | ``N``, ``N_t``, ``N_t_R`` and ``N_t_L`` all refer to the weighted sum,\n",
" | if ``sample_weight`` is passed.\n",
" | \n",
" | .. versionadded:: 0.19\n",
" | \n",
" | min_impurity_split : float, default=0\n",
" | Threshold for early stopping in tree growth. A node will split\n",
" | if its impurity is above the threshold, otherwise it is a leaf.\n",
" | \n",
" | .. deprecated:: 0.19\n",
" | ``min_impurity_split`` has been deprecated in favor of\n",
" | ``min_impurity_decrease`` in 0.19. The default value of\n",
" | ``min_impurity_split`` has changed from 1e-7 to 0 in 0.23 and it\n",
" | will be removed in 0.25. Use ``min_impurity_decrease`` instead.\n",
" | \n",
" | class_weight : dict, list of dict or \"balanced\", default=None\n",
" | Weights associated with classes in the form ``{class_label: weight}``.\n",
" | If None, all classes are supposed to have weight one. For\n",
" | multi-output problems, a list of dicts can be provided in the same\n",
" | order as the columns of y.\n",
" | \n",
" | Note that for multioutput (including multilabel) weights should be\n",
" | defined for each class of every column in its own dict. For example,\n",
" | for four-class multilabel classification weights should be\n",
" | [{0: 1, 1: 1}, {0: 1, 1: 5}, {0: 1, 1: 1}, {0: 1, 1: 1}] instead of\n",
" | [{1:1}, {2:5}, {3:1}, {4:1}].\n",
" | \n",
" | The \"balanced\" mode uses the values of y to automatically adjust\n",
" | weights inversely proportional to class frequencies in the input data\n",
" | as ``n_samples / (n_classes * np.bincount(y))``\n",
" | \n",
" | For multi-output, the weights of each column of y will be multiplied.\n",
" | \n",
" | Note that these weights will be multiplied with sample_weight (passed\n",
" | through the fit method) if sample_weight is specified.\n",
" | \n",
" | presort : deprecated, default='deprecated'\n",
" | This parameter is deprecated and will be removed in v0.24.\n",
" | \n",
" | .. deprecated:: 0.22\n",
" | \n",
" | ccp_alpha : non-negative float, default=0.0\n",
" | Complexity parameter used for Minimal Cost-Complexity Pruning. The\n",
" | subtree with the largest cost complexity that is smaller than\n",
" | ``ccp_alpha`` will be chosen. By default, no pruning is performed. See\n",
" | :ref:`minimal_cost_complexity_pruning` for details.\n",
" | \n",
" | .. versionadded:: 0.22\n",
" | \n",
" | Attributes\n",
" | ----------\n",
" | classes_ : ndarray of shape (n_classes,) or list of ndarray\n",
" | The classes labels (single output problem),\n",
" | or a list of arrays of class labels (multi-output problem).\n",
" | \n",
" | feature_importances_ : ndarray of shape (n_features,)\n",
" | The impurity-based feature importances.\n",
" | The higher, the more important the feature.\n",
" | The importance of a feature is computed as the (normalized)\n",
" | total reduction of the criterion brought by that feature. It is also\n",
" | known as the Gini importance [4]_.\n",
" | \n",
" | Warning: impurity-based feature importances can be misleading for\n",
" | high cardinality features (many unique values). See\n",
" | :func:`sklearn.inspection.permutation_importance` as an alternative.\n",
" | \n",
" | max_features_ : int\n",
" | The inferred value of max_features.\n",
" | \n",
" | n_classes_ : int or list of int\n",
" | The number of classes (for single output problems),\n",
" | or a list containing the number of classes for each\n",
" | output (for multi-output problems).\n",
" | \n",
" | n_features_ : int\n",
" | The number of features when ``fit`` is performed.\n",
" | \n",
" | n_outputs_ : int\n",
" | The number of outputs when ``fit`` is performed.\n",
" | \n",
" | tree_ : Tree\n",
" | The underlying Tree object. Please refer to\n",
" | ``help(sklearn.tree._tree.Tree)`` for attributes of Tree object and\n",
" | :ref:`sphx_glr_auto_examples_tree_plot_unveil_tree_structure.py`\n",
" | for basic usage of these attributes.\n",
" | \n",
" | See Also\n",
" | --------\n",
" | DecisionTreeRegressor : A decision tree regressor.\n",
" | \n",
" | Notes\n",
" | -----\n",
" | The default values for the parameters controlling the size of the trees\n",
" | (e.g. ``max_depth``, ``min_samples_leaf``, etc.) lead to fully grown and\n",
" | unpruned trees which can potentially be very large on some data sets. To\n",
" | reduce memory consumption, the complexity and size of the trees should be\n",
" | controlled by setting those parameter values.\n",
" | \n",
" | References\n",
" | ----------\n",
" | \n",
" | .. [1] https://en.wikipedia.org/wiki/Decision_tree_learning\n",
" | \n",
" | .. [2] L. Breiman, J. Friedman, R. Olshen, and C. Stone, \"Classification\n",
" | and Regression Trees\", Wadsworth, Belmont, CA, 1984.\n",
" | \n",
" | .. [3] T. Hastie, R. Tibshirani and J. Friedman. \"Elements of Statistical\n",
" | Learning\", Springer, 2009.\n",
" | \n",
" | .. [4] L. Breiman, and A. Cutler, \"Random Forests\",\n",
" | https://www.stat.berkeley.edu/~breiman/RandomForests/cc_home.htm\n",
" | \n",
" | Examples\n",
" | --------\n",
" | >>> from sklearn.datasets import load_iris\n",
" | >>> from sklearn.model_selection import cross_val_score\n",
" | >>> from sklearn.tree import DecisionTreeClassifier\n",
" | >>> clf = DecisionTreeClassifier(random_state=0)\n",
" | >>> iris = load_iris()\n",
" | >>> cross_val_score(clf, iris.data, iris.target, cv=10)\n",
" | ... # doctest: +SKIP\n",
" | ...\n",
" | array([ 1. , 0.93..., 0.86..., 0.93..., 0.93...,\n",
" | 0.93..., 0.93..., 1. , 0.93..., 1. ])\n",
" | \n",
" | Method resolution order:\n",
" | DecisionTreeClassifier\n",
" | sklearn.base.ClassifierMixin\n",
" | BaseDecisionTree\n",
" | sklearn.base.MultiOutputMixin\n",
" | sklearn.base.BaseEstimator\n",
" | builtins.object\n",
" | \n",
" | Methods defined here:\n",
" | \n",
" | __init__(self, *, criterion='gini', splitter='best', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None, random_state=None, max_leaf_nodes=None, min_impurity_decrease=0.0, min_impurity_split=None, class_weight=None, presort='deprecated', ccp_alpha=0.0)\n",
" | Initialize self. See help(type(self)) for accurate signature.\n",
" | \n",
" | fit(self, X, y, sample_weight=None, check_input=True, X_idx_sorted=None)\n",
" | Build a decision tree classifier from the training set (X, y).\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The training input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csc_matrix``.\n",
" | \n",
" | y : array-like of shape (n_samples,) or (n_samples, n_outputs)\n",
" | The target values (class labels) as integers or strings.\n",
" | \n",
" | sample_weight : array-like of shape (n_samples,), default=None\n",
" | Sample weights. If None, then samples are equally weighted. Splits\n",
" | that would create child nodes with net zero or negative weight are\n",
" | ignored while searching for a split in each node. Splits are also\n",
" | ignored if they would result in any single class carrying a\n",
" | negative weight in either child node.\n",
" | \n",
" | check_input : bool, default=True\n",
" | Allow to bypass several input checking.\n",
" | Don't use this parameter unless you know what you do.\n",
" | \n",
" | X_idx_sorted : array-like of shape (n_samples, n_features), default=None\n",
" | The indexes of the sorted training input samples. If many tree\n",
" | are grown on the same dataset, this allows the ordering to be\n",
" | cached between trees. If None, the data will be sorted here.\n",
" | Don't use this parameter unless you know what to do.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | self : DecisionTreeClassifier\n",
" | Fitted estimator.\n",
" | \n",
" | predict_log_proba(self, X)\n",
" | Predict class log-probabilities of the input samples X.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csr_matrix``.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | proba : ndarray of shape (n_samples, n_classes) or list of n_outputs such arrays if n_outputs > 1\n",
" | The class log-probabilities of the input samples. The order of the\n",
" | classes corresponds to that in the attribute :term:`classes_`.\n",
" | \n",
" | predict_proba(self, X, check_input=True)\n",
" | Predict class probabilities of the input samples X.\n",
" | \n",
" | The predicted class probability is the fraction of samples of the same\n",
" | class in a leaf.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csr_matrix``.\n",
" | \n",
" | check_input : bool, default=True\n",
" | Allow to bypass several input checking.\n",
" | Don't use this parameter unless you know what you do.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | proba : ndarray of shape (n_samples, n_classes) or list of n_outputs such arrays if n_outputs > 1\n",
" | The class probabilities of the input samples. The order of the\n",
" | classes corresponds to that in the attribute :term:`classes_`.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data and other attributes defined here:\n",
" | \n",
" | __abstractmethods__ = frozenset()\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Methods inherited from sklearn.base.ClassifierMixin:\n",
" | \n",
" | score(self, X, y, sample_weight=None)\n",
" | Return the mean accuracy on the given test data and labels.\n",
" | \n",
" | In multi-label classification, this is the subset accuracy\n",
" | which is a harsh metric since you require for each sample that\n",
" | each label set be correctly predicted.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : array-like of shape (n_samples, n_features)\n",
" | Test samples.\n",
" | \n",
" | y : array-like of shape (n_samples,) or (n_samples, n_outputs)\n",
" | True labels for X.\n",
" | \n",
" | sample_weight : array-like of shape (n_samples,), default=None\n",
" | Sample weights.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | score : float\n",
" | Mean accuracy of self.predict(X) wrt. y.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data descriptors inherited from sklearn.base.ClassifierMixin:\n",
" | \n",
" | __dict__\n",
" | dictionary for instance variables (if defined)\n",
" | \n",
" | __weakref__\n",
" | list of weak references to the object (if defined)\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Methods inherited from BaseDecisionTree:\n",
" | \n",
" | apply(self, X, check_input=True)\n",
" | Return the index of the leaf that each sample is predicted as.\n",
" | \n",
" | .. versionadded:: 0.17\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csr_matrix``.\n",
" | \n",
" | check_input : bool, default=True\n",
" | Allow to bypass several input checking.\n",
" | Don't use this parameter unless you know what you do.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | X_leaves : array-like of shape (n_samples,)\n",
" | For each datapoint x in X, return the index of the leaf x\n",
" | ends up in. Leaves are numbered within\n",
" | ``[0; self.tree_.node_count)``, possibly with gaps in the\n",
" | numbering.\n",
" | \n",
" | cost_complexity_pruning_path(self, X, y, sample_weight=None)\n",
" | Compute the pruning path during Minimal Cost-Complexity Pruning.\n",
" | \n",
" | See :ref:`minimal_cost_complexity_pruning` for details on the pruning\n",
" | process.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The training input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csc_matrix``.\n",
" | \n",
" | y : array-like of shape (n_samples,) or (n_samples, n_outputs)\n",
" | The target values (class labels) as integers or strings.\n",
" | \n",
" | sample_weight : array-like of shape (n_samples,), default=None\n",
" | Sample weights. If None, then samples are equally weighted. Splits\n",
" | that would create child nodes with net zero or negative weight are\n",
" | ignored while searching for a split in each node. Splits are also\n",
" | ignored if they would result in any single class carrying a\n",
" | negative weight in either child node.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | ccp_path : :class:`~sklearn.utils.Bunch`\n",
" | Dictionary-like object, with the following attributes.\n",
" | \n",
" | ccp_alphas : ndarray\n",
" | Effective alphas of subtree during pruning.\n",
" | \n",
" | impurities : ndarray\n",
" | Sum of the impurities of the subtree leaves for the\n",
" | corresponding alpha value in ``ccp_alphas``.\n",
" | \n",
" | decision_path(self, X, check_input=True)\n",
" | Return the decision path in the tree.\n",
" | \n",
" | .. versionadded:: 0.18\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csr_matrix``.\n",
" | \n",
" | check_input : bool, default=True\n",
" | Allow to bypass several input checking.\n",
" | Don't use this parameter unless you know what you do.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | indicator : sparse matrix of shape (n_samples, n_nodes)\n",
" | Return a node indicator CSR matrix where non zero elements\n",
" | indicates that the samples goes through the nodes.\n",
" | \n",
" | get_depth(self)\n",
" | Return the depth of the decision tree.\n",
" | \n",
" | The depth of a tree is the maximum distance between the root\n",
" | and any leaf.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | self.tree_.max_depth : int\n",
" | The maximum depth of the tree.\n",
" | \n",
" | get_n_leaves(self)\n",
" | Return the number of leaves of the decision tree.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | self.tree_.n_leaves : int\n",
" | Number of leaves.\n",
" | \n",
" | predict(self, X, check_input=True)\n",
" | Predict class or regression value for X.\n",
" | \n",
" | For a classification model, the predicted class for each sample in X is\n",
" | returned. For a regression model, the predicted value based on X is\n",
" | returned.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | X : {array-like, sparse matrix} of shape (n_samples, n_features)\n",
" | The input samples. Internally, it will be converted to\n",
" | ``dtype=np.float32`` and if a sparse matrix is provided\n",
" | to a sparse ``csr_matrix``.\n",
" | \n",
" | check_input : bool, default=True\n",
" | Allow to bypass several input checking.\n",
" | Don't use this parameter unless you know what you do.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | y : array-like of shape (n_samples,) or (n_samples, n_outputs)\n",
" | The predicted classes, or the predict values.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data descriptors inherited from BaseDecisionTree:\n",
" | \n",
" | feature_importances_\n",
" | Return the feature importances.\n",
" | \n",
" | The importance of a feature is computed as the (normalized) total\n",
" | reduction of the criterion brought by that feature.\n",
" | It is also known as the Gini importance.\n",
" | \n",
" | Warning: impurity-based feature importances can be misleading for\n",
" | high cardinality features (many unique values). See\n",
" | :func:`sklearn.inspection.permutation_importance` as an alternative.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | feature_importances_ : ndarray of shape (n_features,)\n",
" | Normalized total reduction of criteria by feature\n",
" | (Gini importance).\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Methods inherited from sklearn.base.BaseEstimator:\n",
" | \n",
" | __getstate__(self)\n",
" | \n",
" | __repr__(self, N_CHAR_MAX=700)\n",
" | Return repr(self).\n",
" | \n",
" | __setstate__(self, state)\n",
" | \n",
" | get_params(self, deep=True)\n",
" | Get parameters for this estimator.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | deep : bool, default=True\n",
" | If True, will return the parameters for this estimator and\n",
" | contained subobjects that are estimators.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | params : mapping of string to any\n",
" | Parameter names mapped to their values.\n",
" | \n",
" | set_params(self, **params)\n",
" | Set the parameters of this estimator.\n",
" | \n",
" | The method works on simple estimators as well as on nested objects\n",
" | (such as pipelines). The latter have parameters of the form\n",
" | ``<component>__<parameter>`` so that it's possible to update each\n",
" | component of a nested object.\n",
" | \n",
" | Parameters\n",
" | ----------\n",
" | **params : dict\n",
" | Estimator parameters.\n",
" | \n",
" | Returns\n",
" | -------\n",
" | self : object\n",
" | Estimator instance.\n",
"\n"
]
}
],
"source": [
"help(DecisionTreeClassifier)"
]
},
{
"cell_type": "code",
"execution_count": 169,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DecisionTreeClassifier(max_depth=2)"
]
},
"execution_count": 169,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pruned_tree = DecisionTreeClassifier(max_depth=2)\n",
"pruned_tree.fit(X_train,y_train)"
]
},
{
"cell_type": "code",
"execution_count": 172,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" precision recall f1-score support\n",
"\n",
" Adelie 0.87 0.97 0.92 40\n",
" Chinstrap 0.91 0.78 0.84 27\n",
" Gentoo 1.00 0.97 0.98 33\n",
"\n",
" accuracy 0.92 100\n",
" macro avg 0.93 0.91 0.91 100\n",
"weighted avg 0.92 0.92 0.92 100\n",
"\n",
"\n",
"\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABZEAAAOnCAYAAABRRAhMAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIWXMAABcSAAAXEgFnn9JSAAEAAElEQVR4nOzddZxU1f/H8dehU0IMukNQMVDCAMUCEZQQEbG7+2t3dwcmJhgoCDYKighiKygijVLSzQLn98cM+xN3R1l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pvuuJf5CxZwwf+uofbOe1G2Sl322O/g9Wa0Tpk2nVPOuZgajfekbJW67H1Au5Svkb+/VoeP/Ip2nY+lUq3GbF+nCV17ncL4CRMzj33nvQ9p074zFWs0YrvaTTju1HOynYGbW374eSwXXXEdNRrvyQlnnL/ZrvNvKpQvTwgh231lypSmebM9APh94qT19i1atJhPPvsCINu2E107dWCbsmUZ8+s4xo2fsN6+R3s/C8BlF5xN6Vzqv/7WO+8BcPyx3ShcuPB6+2pUq0rb1vuyevVq3nn/o1y5niRJUm4zRJYkSVuc6tWq0qr5Xmy/XSUA6tetTavme9Gq+V40qFtnk88/YtTXtG53FJ99MZLatWpStkwZvhj5FZ2OOYHHn+mTq+Muv/Zm2nU5lkHJcKhxowYsXrKUPq/0Y6/WhzFy9Dcpr3f2xVdwzsVXMG/efBo1qM82Zcts2gPP5fquveVOTjzzAubOnUf9unVYtnwFbw4cTJv2nflr7rwsx384ZCit2x3FB0OGUrhwIerXq8PYX3/jsM496D9gcJbj170O1ln3Glj39U8LFy1m/0OP5PFn+lC
"text/plain": [
"<Figure size 1800x1200 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"report_model(pruned_tree)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Max Leaf Nodes"
]
},
{
"cell_type": "code",
"execution_count": 185,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DecisionTreeClassifier(max_leaf_nodes=3)"
]
},
"execution_count": 185,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pruned_tree = DecisionTreeClassifier(max_leaf_nodes=3)\n",
"pruned_tree.fit(X_train,y_train)"
]
},
{
"cell_type": "code",
"execution_count": 186,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" precision recall f1-score support\n",
"\n",
" Adelie 0.95 0.95 0.95 40\n",
" Chinstrap 0.91 0.78 0.84 27\n",
" Gentoo 0.86 0.97 0.91 33\n",
"\n",
" accuracy 0.91 100\n",
" macro avg 0.91 0.90 0.90 100\n",
"weighted avg 0.91 0.91 0.91 100\n",
"\n",
"\n",
"\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABZEAAAOnCAYAAABRRAhMAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIWXMAABcSAAAXEgFnn9JSAAEAAElEQVR4nOzdd3QUVRvH8d8QQggJAULvvUjvvVdBAaVKV1BBURQV5BULFhRRQETsqEiRjkjvvffea+gllDRS5/0jYciSbLJAkk3C93NOzpk7e+fuM8nMis/eea5hmqYAAAAAAAAAAIhNGmcHAAAAAAAAAABIvkgiAwAAAAAAAADsIokMAAAAAAAAALCLJDIAAAAAAAAAwC6SyAAAAAAAAAAAu0giAwAAAAAAAADsIokMAAAAAAAAALCLJDIAAAAAAAAAwC6SyAAAAAAAAAAAu0giAwAAAAAAAADsIokMAAAAAAAAALCLJDIAAAAAAAAAwC6SyAAAAAAAAAAAu0giAwAAAAAAAADsIokMAAAAAAAAALCLJDIAAAAAAAAAwC6SyAAAAAAAAAAAu0giAwAAAAAAAADsIokMAAAAAAAAALCLJDIAAAAAAAAAwC6SyAAAAAAAAAAAu0giAwAAAAAAAADsIokMAAAAAAAAALCLJDIAAAAAAAAAwC6SyAAAAAAAAAAAu0giAwAAAAAAAADsIokMAAAAAAAAALCLJDIAAAAAAAAAwC6SyAAAAAAAAAAAu0giAwAAAAAAAADsIokMAAAAAAAAALCLJDIAAAAAAAAAwC6SyAAAAAAAAAAAu0giAwAAAAAAAADsIokMAAAAAAAAALCLJDIAAAAAAAAAwC6SyAAAAAAAAAAAu0giAwAAAAAAAADsIokMAAAAAAAAALCLJDIAAAAAAAAAwC6SyAAAAAAAAAAAu0giAwAAAAAAAADsIokMAAAAAAAAALCLJDIAAAAAAAAAwC6SyAAAAAAAAAAAu0giAwAAAAAAAADsIok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319ZgfrMR62rRptWj2VLV95mkrgSxJRQsX0sKZk1W18v0SGkM//UrBwcEJFgcApCQkkQEAABJIWFioTTsxFgACADyenXv26Z3/feLsMB7LsA8G6cPBAx1aLK9wwQL6eMi7Vvva9RvasHmr3f4r16zX9l17rPa3wz9RJi+vWPsWzJ9PHw4eaLVn/jtfJ06dtjv2+k1bbMo+/fr9N6pRtXK855CQ/Pz89ePvf1ntfr172q21nC5dOo0fNcJqnzt/QVNmzEnsEAEgWSKJDAAA8BjWbtgkV+98cvXOp6ZtbEtO3Nsf/Wfthk0P/R4Tp86wjm/SuoPdfr37D7T69e5//3/qV65Zrx6v9NdTVevKK28x5SpWTrWbPqtvv/9Rt27fjvf9z5zzsTmHe3Uwr12/oW+//1G1mz6rvCUryjN3URWvWEu9+g14pPOUpAOHjujj4SNVp1lr5X+qsjLkLKxcxcqpSv3mGvThZ9p38JBD4zRp3cGK97MRoyRJpmnqv0VL1bX3aypdrZ6yFCgpV+98ySqZlJjnL0krVq9Ttz6vq1SVOsqYp6hyFCmjOs1aa8TocfLz849jxJju3PHT6HE/q16LtspdvLwy5imqEpVqq333Pvp3wWKrjulnI0bFel1KttfWvUX1JOnlN96J9f5x9c7nUGwRERGaO3+Rnu/6kopVqCmPXEWUu3h5NWndQeN/+1MhISEPda6Po1iFmlbsE6fOkCSFhYXpn1lz9WzH7ipavoY8chVRrmLl1LpTDy1YsjzWcY6fPKW3h3yk8jUbyStvMWXKV1wVajXWB59+GeMpiNhE/xwpVqGmzbjvf/y5KtVtquyFy8gzd1GVq9FQQz75Qteu34gxTlhYmP7+Z6Zate+mPCUqKEPOwspXqpLavtBLC5eueMTfUuK
"text/plain": [
"<Figure size 1800x1200 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"report_model(pruned_tree)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Criterion"
]
},
{
"cell_type": "code",
"execution_count": 187,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DecisionTreeClassifier(criterion='entropy')"
]
},
"execution_count": 187,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"entropy_tree = DecisionTreeClassifier(criterion='entropy')\n",
"entropy_tree.fit(X_train,y_train)"
]
},
{
"cell_type": "code",
"execution_count": 188,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" precision recall f1-score support\n",
"\n",
" Adelie 0.95 0.95 0.95 40\n",
" Chinstrap 0.93 0.96 0.95 27\n",
" Gentoo 1.00 0.97 0.98 33\n",
"\n",
" accuracy 0.96 100\n",
" macro avg 0.96 0.96 0.96 100\n",
"weighted avg 0.96 0.96 0.96 100\n",
"\n",
"\n",
"\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABZEAAAOnCAYAAABRRAhMAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIWXMAABcSAAAXEgFnn9JSAAEAAElEQVR4nOzdd3RURR/G8e9ND+mhQwi99957B+lFiqAiKlZEEFGxvCKKiIAKNlABBaT3XkPvvXdCh0AKCSH1vn9ssrJuAgGBUJ7POTmHzMy993d3Y9w8OztjmKaJiIiIiIiIiIiIiEhKHNK7ABERERERERERERF5dClEFhEREREREREREZFUKUQWERERERERERERkVQpRBYRERERERERERGRVClEFhEREREREREREZFUKUQWERERERERERERkVQpRBYRERERERERERGRVClEFhEREREREREREZFUKUQWERERERERERERkVQpRBYRERERERERERGRVClEFhEREREREREREZFUKUQWERERERERERERkVQpRBYRERERERERERGRVClEFhEREREREREREZFUKUQWERERERERERERkVQpRBYRERERERERERGRVClEFhEREREREREREZFUKUQWERERERERERERkVQpRBYRERERERERERGRVClEFhEREREREREREZFUKUQWERERERERERERkVQpRBYRERERERERERGRVClEFhEREREREREREZFUKUQWERERERERERERkVQpRBYRERERERERERGRVClEFhEREREREREREZFUKUQWERERERERERERkVQpRBYRERERERERERGRVClEFhEREREREREREZFUKUQWERERERERERERkVQpRBYRERERERERERGRVClEFhEREREREREREZFUKUQWERERERERERERkVQpRBYRERERERERERGRVClEFhEREREREREREZFUOaV3ASIiIk8zwzAMIEN61yEico9umKZppncRIiIiIvJgKUQWERFJXxmAyPQuQkTkHnkCUeldhIiIiIg8WFrOQkRERERERERERERSpZnIIiIij4hzh3fhkUErW4jIoy3qxg1yFi6T3mWIiIiIyEOkEFlEROQR4ZEhAx4eCpFFRERERETk0aLlLEREREREREREREQkVQqRRURERERERERERCRVCpFFREREREREREREJFUKkUVEREREREREREQkVQqRRURERERERERERCRVCpFFREREREREREREJFUKkUVERB4jpmky/IefKVG5Np7Z8+PsH8CcBYs5FXwGZ/8AerzRx2Z8jzf64OwfwKngM+lU8cPn7B9A/Rbt07uM/+xJuQ8REREREXn8KUQWERF5jEyaNpP3P/0CDw8P3nn9ZT7u34fCBQukd1lyD+q3aI+zf0B6lyH/QVxcHLPnL6Lnm30pVaUufoGF8QkoSMU6TRj2/Y/ExMSkeuzKoHU0av0sGXMXxTdXIWo2bsX02fNve71TwWd4rc/7FChdBY9s+chesBR1mrVlwuRpd1X3iVOn6fbyG+QsXAbP7PkpWbkOX48YRVxc3F2dR0RERESeHk7pXYCIiIik3eLlqwCYM3kc2bJmsbanNtN48McD6N/7DXJmz/ZQ6hN5mhw/eZoO3V/Gy9OTurWq07xJA8IjrrNgyTI++OxLZs9fzPK5U3Fzc7M5burMuTz38ht4e3nRqX1rXF1cmDZ7Hp179OJ08Ef0ffs1u2stX7WGdt1ewjRNnmnckHx5cxMecZ39Bw+xZPkqunfukKaaDx89Tq0mrQgLj6Bdy+bkDgxg6cogBg4awsYt25g58XccHDTPRERERERsKUQWERF5jFy8dBnAJkC+nezZspI9W9YHWZLIIyUsPJwz585TsljRB34tL08Pfhj2Jd07dSBDBndre1TUJ9Rv2YHN23bw09jx9HnzVZv63uz3AW5urgQtmkXxooUBeK/361So3ZiPBw+ldYum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jtmd9+P+feyeS4Dc/woIw8IjqN20Ne7u7nRs05KI65FMnTWHZ194lQXT/qJhvdr3/Ji8N/B/bNi8jWaNGlC/Tk1mzl3I2+99hIuzM3v2H2DarHk0a9SAurWrM3PuQt4b+D+yZslE5/Zt7M71wy+/sSJoHS2bNaZOjWosWLKMQUNHEJ+QgJ+PD58PHU7LZo2pVa0KC5cu5+sRo/D08GDAu2/dc/0Am7ZuZ+LUmUybNZer10JxcnKiYd1atG3Z7D+d935wdrK8zHZ0dLRpTw6VG9SpZXdM/To1+fTLbwha90/wbJom02fPw9/Pl3q1a7B73wFWr91AfFwcxYoWomHd2jg5pe0lffJ569WuaddXtWJ5PDwysHnbDmJiYnB1dU3bjYqIiIjIU0EhsoiIyGOgdo1q1K5RjaD1Gzl95iyfDOj7n8+5dGUQo4cP4ZUXnrO2/TruL954dwC9+w9k8azJdsccO3GS3RtX4uPtDcAnA96lesMW/PzbeDq1a031KhUBOHDoCO+8/zElihVh2ZypZPT3s55j6MhRfPT5EEb98jvvvtXL5vwrgtbafMz+fvnim5EErdvIh31789mH/TAMA4Dr1yNp2PpZ+n88iDbPNCXHv9aO3rpjFzvXLSdnjuwADBr4PuVrNWTKjDkM+ewj6/iVQev46+/plCxelLWL5+DhkQGAzz7oR41GLe3q+WRA3zQ9l3v2HeDlF55j1LAvrevUdmrXimbtuzLyx1//U4i8/+Bhdq5bTtYsmQHo88arFK9Um/4fDyJL5ox2fcUq1uKb735MMURes34TW1cvpkC+vEn39y5FK9Rk5I+/4uXpyZZViyiYP5+1r0j5Goz88Vf6vf1amgPQZCdOnWbS1JlMnDqDYydOAVC1UgU6d2hDh9YtyJTR3+6YU8FnmPCv2b138l//Gxs3cQoADerahsVHj58EIH++PHbHJD9+x06ctLadPB3MtdAwKpQrzTsDPubHMeNsjimYPy/T//yNYkUK3bGmo8d
"text/plain": [
"<Figure size 1800x1200 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"report_model(entropy_tree)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}