{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
" \n",
"___\n",
"# Decision Trees and Random Forests in Python"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This is the code for the lecture video which goes over tree methods in Python. Reference the video lecture for the full explanation of the code!\n",
"\n",
"I also wrote a [blog post](https://medium.com/@josemarcialportilla/enchanted-random-forest-b08d418cb411#.hh7n1co54) explaining the general logic of decision trees and random forests which you can check out. \n",
"\n",
"## Import Libraries"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Get the Data"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df = pd.read_csv('kyphosis.csv')"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"
\n", " | Kyphosis | \n", "Age | \n", "Number | \n", "Start | \n", "
---|---|---|---|---|
0 | \n", "absent | \n", "71 | \n", "3 | \n", "5 | \n", "
1 | \n", "absent | \n", "158 | \n", "3 | \n", "14 | \n", "
2 | \n", "present | \n", "128 | \n", "4 | \n", "5 | \n", "
3 | \n", "absent | \n", "2 | \n", "5 | \n", "1 | \n", "
4 | \n", "absent | \n", "1 | \n", "4 | \n", "15 | \n", "