Skip to content

Commit

Permalink
Decision Trees
Browse files Browse the repository at this point in the history
  • Loading branch information
tuanavu committed Mar 18, 2016
1 parent ebe0ce1 commit 2cfde70
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {
"collapsed": false,
"scrolled": false
Expand Down Expand Up @@ -73,7 +73,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 7,
"metadata": {
"collapsed": false
},
Expand All @@ -91,7 +91,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 8,
"metadata": {
"collapsed": false
},
Expand All @@ -118,7 +118,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 9,
"metadata": {
"collapsed": false,
"scrolled": false
Expand All @@ -143,7 +143,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 10,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -263,7 +263,7 @@
"You can use print_rows(num_rows=m, num_columns=n) to print more rows and columns."
]
},
"execution_count": 6,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -288,7 +288,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 11,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -357,7 +357,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 12,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -385,7 +385,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 13,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -420,7 +420,7 @@
" 'emp_length.n/a']"
]
},
"execution_count": 9,
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -433,7 +433,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 14,
"metadata": {
"collapsed": false
},
Expand All @@ -452,7 +452,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 15,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -594,7 +594,7 @@
"[1 rows x 26 columns]"
]
},
"execution_count": 16,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -612,7 +612,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 16,
"metadata": {
"collapsed": false
},
Expand All @@ -625,7 +625,7 @@
"[0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, ... ]"
]
},
"execution_count": 11,
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -645,7 +645,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 17,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -675,7 +675,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 18,
"metadata": {
"collapsed": true
},
Expand Down Expand Up @@ -716,7 +716,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 19,
"metadata": {
"collapsed": true
},
Expand Down Expand Up @@ -746,7 +746,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 20,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -822,7 +822,7 @@
},
{
"cell_type": "code",
"execution_count": 35,
"execution_count": 21,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -879,7 +879,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 22,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -920,7 +920,7 @@
},
{
"cell_type": "code",
"execution_count": 84,
"execution_count": 23,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -963,7 +963,7 @@
},
{
"cell_type": "code",
"execution_count": 85,
"execution_count": 24,
"metadata": {
"collapsed": false
},
Expand All @@ -986,7 +986,7 @@
" return create_leaf(target_values)\n",
" \n",
" # Stopping condition 2 (check if there are remaining features to consider splitting on)\n",
" if remaining_features == 0: ## YOUR CODE HERE\n",
" if remaining_features == []: ## YOUR CODE HERE\n",
" print \"Stopping condition 2 reached.\" \n",
" # If there are no remaining features to consider, make current node a leaf node\n",
" return create_leaf(target_values) \n",
Expand Down Expand Up @@ -1038,7 +1038,7 @@
},
{
"cell_type": "code",
"execution_count": 86,
"execution_count": 25,
"metadata": {
"collapsed": false
},
Expand All @@ -1059,7 +1059,7 @@
},
{
"cell_type": "code",
"execution_count": 87,
"execution_count": 26,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -1135,7 +1135,7 @@
},
{
"cell_type": "code",
"execution_count": 88,
"execution_count": 27,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -1287,7 +1287,7 @@
},
{
"cell_type": "code",
"execution_count": 89,
"execution_count": 28,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -1319,7 +1319,7 @@
},
{
"cell_type": "code",
"execution_count": 90,
"execution_count": 29,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -1355,7 +1355,7 @@
" 'term. 60 months': 1L}"
]
},
"execution_count": 90,
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1366,7 +1366,7 @@
},
{
"cell_type": "code",
"execution_count": 91,
"execution_count": 30,
"metadata": {
"collapsed": false
},
Expand All @@ -1392,7 +1392,7 @@
},
{
"cell_type": "code",
"execution_count": 92,
"execution_count": 31,
"metadata": {
"collapsed": false
},
Expand All @@ -1415,7 +1415,7 @@
"-1"
]
},
"execution_count": 92,
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -1472,7 +1472,7 @@
},
{
"cell_type": "code",
"execution_count": 101,
"execution_count": 32,
"metadata": {
"collapsed": false
},
Expand All @@ -1496,7 +1496,7 @@
},
{
"cell_type": "code",
"execution_count": 102,
"execution_count": 33,
"metadata": {
"collapsed": false
},
Expand All @@ -1507,7 +1507,7 @@
"0.3837785437311504"
]
},
"execution_count": 102,
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -1539,7 +1539,7 @@
},
{
"cell_type": "code",
"execution_count": 97,
"execution_count": 34,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -1567,7 +1567,7 @@
},
{
"cell_type": "code",
"execution_count": 98,
"execution_count": 35,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -1608,7 +1608,7 @@
},
{
"cell_type": "code",
"execution_count": 99,
"execution_count": 36,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -1643,7 +1643,7 @@
},
{
"cell_type": "code",
"execution_count": 100,
"execution_count": 37,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -1685,12 +1685,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 38,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" term. 36 months\n",
" |---------------|----------------|\n",
" | |\n",
" | |\n",
" | |\n",
" [grade.D == 0] [grade.D == 1] \n",
" | |\n",
" | |\n",
" | |\n",
" (subtree) (leaf, label: -1)\n"
]
}
],
"source": [
"print_stump(my_decision_tree['right'], my_decision_tree['splitting_feature'])"
]
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 2cfde70

Please sign in to comment.