{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "2X8leJ-Itsg6"
},
"source": [
"# Decision Tree"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "uJf3Fp-_u9wZ"
},
"source": [
"## Important Considerations\n",
"\n",
"\n",
"| PROS | CONS |\n",
"| ---- | ----- |\n",
"| Easy to visualize and Interpret | Prone to overfitting |\n",
"| No normalization of Data Necessary | Ensemble needed for better performance |\n",
"| Handles mixed feature types | |"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "vimY-ObBvL0d"
},
"source": [
"\n",
"## Iris Example\n",
"\n",
"\n",
"**Use measurements to predict species**\n",
"\n",
"\n",
"\n",
"Iris Example\n",
"Use measurements to predict species"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "SCBUOfq6u8PQ"
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"from sklearn.datasets import load_iris\n",
"from sklearn import tree\n",
"from sklearn.datasets import load_iris\n",
"from sklearn.tree import DecisionTreeClassifier\n",
"from sklearn.model_selection import train_test_split"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 204
},
"colab_type": "code",
"executionInfo": {
"elapsed": 5708,
"status": "ok",
"timestamp": 1576533970637,
"user": {
"displayName": "Daniele Grotti",
"photoUrl": "",
"userId": "05993002232846155126"
},
"user_tz": -60
},
"id": "85h8G2dlvPnV",
"outputId": "23188906-29b6-4fcd-829e-d62562498cbe"
},
"outputs": [
{
"data": {
"text/html": [
"
\n", " | sepal_length | \n", "sepal_width | \n", "petal_length | \n", "petal_width | \n", "species | \n", "
---|---|---|---|---|---|
0 | \n", "5.1 | \n", "3.5 | \n", "1.4 | \n", "0.2 | \n", "setosa | \n", "
1 | \n", "4.9 | \n", "3.0 | \n", "1.4 | \n", "0.2 | \n", "setosa | \n", "
2 | \n", "4.7 | \n", "3.2 | \n", "1.3 | \n", "0.2 | \n", "setosa | \n", "
3 | \n", "4.6 | \n", "3.1 | \n", "1.5 | \n", "0.2 | \n", "setosa | \n", "
4 | \n", "5.0 | \n", "3.6 | \n", "1.4 | \n", "0.2 | \n", "setosa | \n", "