{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"using DataFrames, RDatasets"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"
| Pharvis | LnhhExp | Age | Sex | Married | Educ | Illness | Injury | Illdays | Actdays | Insurance | Commune |
---|
1 | 0 | 2.730363 | 3.7612 | male | 1 | 2 | 1 | 0 | 7 | 0 | 0 | 192 |
---|
2 | 0 | 2.737248 | 2.944439 | female | 0 | 0 | 1 | 0 | 4 | 0 | 0 | 167 |
---|
3 | 0 | 2.266935 | 2.56495 | male | 0 | 4 | 0 | 0 | 0 | 0 | 1 | 76 |
---|
4 | 1 | 2.392753 | 3.637586 | female | 1 | 3 | 1 | 0 | 3 | 0 | 1 | 123 |
---|
5 | 1 | 3.105335 | 3.295837 | male | 1 | 3 | 1 | 0 | 10 | 0 | 0 | 148 |
---|
6 | 0 | 3.760884 | 3.367296 | male | 1 | 9 | 0 | 0 | 0 | 0 | 1 | 20 |
---|
7 | 0 | 3.155609 | 3.663562 | female | 1 | 2 | 0 | 0 | 0 | 0 | 1 | 40 |
---|
8 | 0 | 3.724682 | 2.197225 | male | 0 | 5 | 0 | 0 | 0 | 0 | 1 | 57 |
---|
9 | 2 | 2.861691 | 3.7612 | female | 1 | 2 | 2 | 0 | 4 | 0 | 0 | 49 |
---|
10 | 3 | 2.615077 | 4.234107 | male | 1 | 0 | 1 | 0 | 7 | 0 | 0 | 170 |
---|
11 | 1 | 2.653243 | 2.772589 | male | 0 | 4 | 1 | 0 | 1 | 0 | 0 | 40 |
---|
12 | 1 | 2.139857 | 3.663562 | female | 1 | 2 | 2 | 0 | 5 | 0 | 0 | 127 |
---|
13 | 2 | 2.625683 | 3.555348 | female | 1 | 3 | 1 | 0 | 3 | 0 | 0 | 106 |
---|
14 | 1 | 2.767746 | 1.94591 | female | 0 | 5 | 2 | 0 | 3 | 0 | 0 | 168 |
---|
15 | 0 | 2.871242 | 2.302585 | male | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 185 |
---|
16 | 2 | 1.983811 | 3.135494 | male | 1 | 4 | 3 | 0 | 10 | 0 | 0 | 41 |
---|
17 | 0 | 1.260201 | 3.091043 | male | 0 | 4 | 0 | 0 | 0 | 0 | 0 | 106 |
---|
18 | 0 | 2.298178 | 3.401197 | male | 1 | 2 | 0 | 0 | 0 | 0 | 0 | 141 |
---|
19 | 3 | 2.132508 | 3.332205 | male | 1 | 4 | 3 | 0 | 10 | 0 | 0 | 61 |
---|
20 | 0 | 2.000231 | 3.258096 | male | 1 | 3 | 0 | 0 | 0 | 0 | 0 | 159 |
---|
21 | 0 | 2.018375 | 3.218876 | male | 1 | 6 | 1 | 0 | 7 | 0 | 0 | 121 |
---|
22 | 1 | 1.886142 | 2.639057 | female | 0 | 2 | 1 | 0 | 3 | 0 | 0 | 56 |
---|
23 | 10 | 2.953125 | 1.098612 | female | 0 | 2 | 2 | 0 | 4 | 0 | 0 | 34 |
---|
24 | 0 | 2.378481 | 3.526361 | male | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 127 |
---|
25 | 0 | 1.574376 | 3.555348 | male | 1 | 2 | 0 | 0 | 0 | 0 | 0 | 135 |
---|
26 | 3 | 2.495514 | 3.637586 | female | 1 | 3 | 1 | 0 | 5 | 0 | 0 | 147 |
---|
27 | 1 | 2.318077 | 3.7612 | male | 1 | 4 | 1 | 0 | 5 | 0 | 0 | 94 |
---|
28 | 0 | 2.029045 | 4.248495 | female | 1 | 3 | 1 | 0 | 30 | 0 | 0 | 125 |
---|
29 | 1 | 1.788754 | 3.610918 | female | 1 | 3 | 3 | 0 | 3 | 0 | 0 | 79 |
---|
30 | 0 | 2.091107 | 2.079442 | female | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 143 |
---|
⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
---|
"
],
"text/plain": [
"27765x12 DataFrame\n",
"| Row | Pharvis | LnhhExp | Age | Sex | Married | Educ | Illness |\n",
"|-------|---------|---------|---------|----------|---------|------|---------|\n",
"| 1 | 0 | 2.73036 | 3.7612 | \"male\" | 1 | 2 | 1 |\n",
"| 2 | 0 | 2.73725 | 2.94444 | \"female\" | 0 | 0 | 1 |\n",
"| 3 | 0 | 2.26694 | 2.56495 | \"male\" | 0 | 4 | 0 |\n",
"| 4 | 1 | 2.39275 | 3.63759 | \"female\" | 1 | 3 | 1 |\n",
"| 5 | 1 | 3.10534 | 3.29584 | \"male\" | 1 | 3 | 1 |\n",
"| 6 | 0 | 3.76088 | 3.3673 | \"male\" | 1 | 9 | 0 |\n",
"| 7 | 0 | 3.15561 | 3.66356 | \"female\" | 1 | 2 | 0 |\n",
"| 8 | 0 | 3.72468 | 2.19722 | \"male\" | 0 | 5 | 0 |\n",
"| 9 | 2 | 2.86169 | 3.7612 | \"female\" | 1 | 2 | 2 |\n",
"| 10 | 3 | 2.61508 | 4.23411 | \"male\" | 1 | 0 | 1 |\n",
"| 11 | 1 | 2.65324 | 2.77259 | \"male\" | 0 | 4 | 1 |\n",
"⋮\n",
"| 27754 | 1 | 3.22879 | 3.98898 | \"female\" | 1 | 9 | 1 |\n",
"| 27755 | 0 | 2.60798 | 3.82864 | \"male\" | 1 | 2 | 1 |\n",
"| 27756 | 0 | 2.23453 | 3.97029 | \"female\" | 1 | 3 | 0 |\n",
"| 27757 | 0 | 1.83282 | 3.61092 | \"male\" | 1 | 0 | 1 |\n",
"| 27758 | 0 | 1.67896 | 4.15888 | \"male\" | 1 | 2 | 0 |\n",
"| 27759 | 0 | 2.28975 | 2.89037 | \"male\" | 0 | 0 | 0 |\n",
"| 27760 | 0 | 2.15735 | 4.00733 | \"female\" | 1 | 4 | 1 |\n",
"| 27761 | 0 | 1.84729 | 1.60944 | \"female\" | 0 | 5 | 2 |\n",
"| 27762 | 0 | 2.46146 | 2.83321 | \"female\" | 0 | 6 | 0 |\n",
"| 27763 | 0 | 2.46026 | 2.56495 | \"female\" | 0 | 5 | 0 |\n",
"| 27764 | 0 | 1.92017 | 4.00733 | \"female\" | 1 | 4 | 2 |\n",
"| 27765 | 3 | 2.46883 | 3.13549 | \"male\" | 0 | 3 | 2 |\n",
"\n",
"| Row | Injury | Illdays | Actdays | Insurance | Commune |\n",
"|-------|--------|---------|---------|-----------|---------|\n",
"| 1 | 0 | 7 | 0 | 0 | 192 |\n",
"| 2 | 0 | 4 | 0 | 0 | 167 |\n",
"| 3 | 0 | 0 | 0 | 1 | 76 |\n",
"| 4 | 0 | 3 | 0 | 1 | 123 |\n",
"| 5 | 0 | 10 | 0 | 0 | 148 |\n",
"| 6 | 0 | 0 | 0 | 1 | 20 |\n",
"| 7 | 0 | 0 | 0 | 1 | 40 |\n",
"| 8 | 0 | 0 | 0 | 1 | 57 |\n",
"| 9 | 0 | 4 | 0 | 0 | 49 |\n",
"| 10 | 0 | 7 | 0 | 0 | 170 |\n",
"| 11 | 0 | 1 | 0 | 0 | 40 |\n",
"⋮\n",
"| 27754 | 0 | 3 | 0 | 0 | 86 |\n",
"| 27755 | 0 | 10 | 0 | 0 | 90 |\n",
"| 27756 | 0 | 0 | 0 | 0 | 90 |\n",
"| 27757 | 0 | 1 | 0 | 0 | 90 |\n",
"| 27758 | 0 | 0 | 0 | 0 | 90 |\n",
"| 27759 | 0 | 0 | 0 | 0 | 91 |\n",
"| 27760 | 0 | 30 | 0 | 1 | 108 |\n",
"| 27761 | 0 | 3 | 0 | 0 | 115 |\n",
"| 27762 | 0 | 0 | 0 | 0 | 115 |\n",
"| 27763 | 0 | 0 | 0 | 0 | 116 |\n",
"| 27764 | 0 | 20 | 0 | 1 | 116 |\n",
"| 27765 | 0 | 7 | 0 | 0 | 119 |"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vn = dataset(\"Ecdat\",\"VietNamI\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#Predicting \"Days Ill\" based on historic data"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"27765-element DataArray{Int32,1}:\n",
" 7\n",
" 4\n",
" 0\n",
" 3\n",
" 10\n",
" 0\n",
" 0\n",
" 0\n",
" 4\n",
" 7\n",
" 1\n",
" 5\n",
" 3\n",
" ⋮\n",
" 3\n",
" 10\n",
" 0\n",
" 1\n",
" 0\n",
" 0\n",
" 30\n",
" 3\n",
" 0\n",
" 0\n",
" 20\n",
" 7"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"days_ill = vn[:Illdays]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###We've isolated the signal we want to analyze, now we remove it from the feature set"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
" | Pharvis | LnhhExp | Age | Sex | Married | Educ | Illness | Injury | Actdays | Insurance | Commune |
---|
1 | 0 | 2.730363 | 3.7612 | male | 1 | 2 | 1 | 0 | 0 | 0 | 192 |
---|
2 | 0 | 2.737248 | 2.944439 | female | 0 | 0 | 1 | 0 | 0 | 0 | 167 |
---|
3 | 0 | 2.266935 | 2.56495 | male | 0 | 4 | 0 | 0 | 0 | 1 | 76 |
---|
4 | 1 | 2.392753 | 3.637586 | female | 1 | 3 | 1 | 0 | 0 | 1 | 123 |
---|
5 | 1 | 3.105335 | 3.295837 | male | 1 | 3 | 1 | 0 | 0 | 0 | 148 |
---|
6 | 0 | 3.760884 | 3.367296 | male | 1 | 9 | 0 | 0 | 0 | 1 | 20 |
---|
7 | 0 | 3.155609 | 3.663562 | female | 1 | 2 | 0 | 0 | 0 | 1 | 40 |
---|
8 | 0 | 3.724682 | 2.197225 | male | 0 | 5 | 0 | 0 | 0 | 1 | 57 |
---|
9 | 2 | 2.861691 | 3.7612 | female | 1 | 2 | 2 | 0 | 0 | 0 | 49 |
---|
10 | 3 | 2.615077 | 4.234107 | male | 1 | 0 | 1 | 0 | 0 | 0 | 170 |
---|
11 | 1 | 2.653243 | 2.772589 | male | 0 | 4 | 1 | 0 | 0 | 0 | 40 |
---|
12 | 1 | 2.139857 | 3.663562 | female | 1 | 2 | 2 | 0 | 0 | 0 | 127 |
---|
13 | 2 | 2.625683 | 3.555348 | female | 1 | 3 | 1 | 0 | 0 | 0 | 106 |
---|
14 | 1 | 2.767746 | 1.94591 | female | 0 | 5 | 2 | 0 | 0 | 0 | 168 |
---|
15 | 0 | 2.871242 | 2.302585 | male | 0 | 0 | 0 | 0 | 0 | 0 | 185 |
---|
16 | 2 | 1.983811 | 3.135494 | male | 1 | 4 | 3 | 0 | 0 | 0 | 41 |
---|
17 | 0 | 1.260201 | 3.091043 | male | 0 | 4 | 0 | 0 | 0 | 0 | 106 |
---|
18 | 0 | 2.298178 | 3.401197 | male | 1 | 2 | 0 | 0 | 0 | 0 | 141 |
---|
19 | 3 | 2.132508 | 3.332205 | male | 1 | 4 | 3 | 0 | 0 | 0 | 61 |
---|
20 | 0 | 2.000231 | 3.258096 | male | 1 | 3 | 0 | 0 | 0 | 0 | 159 |
---|
21 | 0 | 2.018375 | 3.218876 | male | 1 | 6 | 1 | 0 | 0 | 0 | 121 |
---|
22 | 1 | 1.886142 | 2.639057 | female | 0 | 2 | 1 | 0 | 0 | 0 | 56 |
---|
23 | 10 | 2.953125 | 1.098612 | female | 0 | 2 | 2 | 0 | 0 | 0 | 34 |
---|
24 | 0 | 2.378481 | 3.526361 | male | 1 | 0 | 0 | 0 | 0 | 0 | 127 |
---|
25 | 0 | 1.574376 | 3.555348 | male | 1 | 2 | 0 | 0 | 0 | 0 | 135 |
---|
26 | 3 | 2.495514 | 3.637586 | female | 1 | 3 | 1 | 0 | 0 | 0 | 147 |
---|
27 | 1 | 2.318077 | 3.7612 | male | 1 | 4 | 1 | 0 | 0 | 0 | 94 |
---|
28 | 0 | 2.029045 | 4.248495 | female | 1 | 3 | 1 | 0 | 0 | 0 | 125 |
---|
29 | 1 | 1.788754 | 3.610918 | female | 1 | 3 | 3 | 0 | 0 | 0 | 79 |
---|
30 | 0 | 2.091107 | 2.079442 | female | 0 | 0 | 0 | 0 | 0 | 0 | 143 |
---|
⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
---|
"
],
"text/plain": [
"27765x11 DataFrame\n",
"| Row | Pharvis | LnhhExp | Age | Sex | Married | Educ | Illness |\n",
"|-------|---------|---------|---------|----------|---------|------|---------|\n",
"| 1 | 0 | 2.73036 | 3.7612 | \"male\" | 1 | 2 | 1 |\n",
"| 2 | 0 | 2.73725 | 2.94444 | \"female\" | 0 | 0 | 1 |\n",
"| 3 | 0 | 2.26694 | 2.56495 | \"male\" | 0 | 4 | 0 |\n",
"| 4 | 1 | 2.39275 | 3.63759 | \"female\" | 1 | 3 | 1 |\n",
"| 5 | 1 | 3.10534 | 3.29584 | \"male\" | 1 | 3 | 1 |\n",
"| 6 | 0 | 3.76088 | 3.3673 | \"male\" | 1 | 9 | 0 |\n",
"| 7 | 0 | 3.15561 | 3.66356 | \"female\" | 1 | 2 | 0 |\n",
"| 8 | 0 | 3.72468 | 2.19722 | \"male\" | 0 | 5 | 0 |\n",
"| 9 | 2 | 2.86169 | 3.7612 | \"female\" | 1 | 2 | 2 |\n",
"| 10 | 3 | 2.61508 | 4.23411 | \"male\" | 1 | 0 | 1 |\n",
"| 11 | 1 | 2.65324 | 2.77259 | \"male\" | 0 | 4 | 1 |\n",
"⋮\n",
"| 27754 | 1 | 3.22879 | 3.98898 | \"female\" | 1 | 9 | 1 |\n",
"| 27755 | 0 | 2.60798 | 3.82864 | \"male\" | 1 | 2 | 1 |\n",
"| 27756 | 0 | 2.23453 | 3.97029 | \"female\" | 1 | 3 | 0 |\n",
"| 27757 | 0 | 1.83282 | 3.61092 | \"male\" | 1 | 0 | 1 |\n",
"| 27758 | 0 | 1.67896 | 4.15888 | \"male\" | 1 | 2 | 0 |\n",
"| 27759 | 0 | 2.28975 | 2.89037 | \"male\" | 0 | 0 | 0 |\n",
"| 27760 | 0 | 2.15735 | 4.00733 | \"female\" | 1 | 4 | 1 |\n",
"| 27761 | 0 | 1.84729 | 1.60944 | \"female\" | 0 | 5 | 2 |\n",
"| 27762 | 0 | 2.46146 | 2.83321 | \"female\" | 0 | 6 | 0 |\n",
"| 27763 | 0 | 2.46026 | 2.56495 | \"female\" | 0 | 5 | 0 |\n",
"| 27764 | 0 | 1.92017 | 4.00733 | \"female\" | 1 | 4 | 2 |\n",
"| 27765 | 3 | 2.46883 | 3.13549 | \"male\" | 0 | 3 | 2 |\n",
"\n",
"| Row | Injury | Actdays | Insurance | Commune |\n",
"|-------|--------|---------|-----------|---------|\n",
"| 1 | 0 | 0 | 0 | 192 |\n",
"| 2 | 0 | 0 | 0 | 167 |\n",
"| 3 | 0 | 0 | 1 | 76 |\n",
"| 4 | 0 | 0 | 1 | 123 |\n",
"| 5 | 0 | 0 | 0 | 148 |\n",
"| 6 | 0 | 0 | 1 | 20 |\n",
"| 7 | 0 | 0 | 1 | 40 |\n",
"| 8 | 0 | 0 | 1 | 57 |\n",
"| 9 | 0 | 0 | 0 | 49 |\n",
"| 10 | 0 | 0 | 0 | 170 |\n",
"| 11 | 0 | 0 | 0 | 40 |\n",
"⋮\n",
"| 27754 | 0 | 0 | 0 | 86 |\n",
"| 27755 | 0 | 0 | 0 | 90 |\n",
"| 27756 | 0 | 0 | 0 | 90 |\n",
"| 27757 | 0 | 0 | 0 | 90 |\n",
"| 27758 | 0 | 0 | 0 | 90 |\n",
"| 27759 | 0 | 0 | 0 | 91 |\n",
"| 27760 | 0 | 0 | 1 | 108 |\n",
"| 27761 | 0 | 0 | 0 | 115 |\n",
"| 27762 | 0 | 0 | 0 | 115 |\n",
"| 27763 | 0 | 0 | 0 | 116 |\n",
"| 27764 | 0 | 0 | 1 | 116 |\n",
"| 27765 | 0 | 0 | 0 | 119 |"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"delete!(vn,:Illdays)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Pkg.add(\"DecisionTree\")\n",
"using DecisionTree"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### The DecisionTree package works with Julia Arrays, so we make those conversions"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"signals = convert(Array,days_ill)\n",
"features = convert(Array,vn);"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"5 methods for generic function build_forest:- build_forest{T<:FloatingPoint,U<:Real}(labels::Array{T<:FloatingPoint,1},features::Array{U<:Real,2},nsubfeatures::Integer,ntrees::Integer) at /home/juser/.julia/v0.3/DecisionTree/src/DecisionTree.jl:415
- build_forest{T<:FloatingPoint,U<:Real}(labels::Array{T<:FloatingPoint,1},features::Array{U<:Real,2},nsubfeatures::Integer,ntrees::Integer,maxlabels) at /home/juser/.julia/v0.3/DecisionTree/src/DecisionTree.jl:415
- build_forest{T<:FloatingPoint,U<:Real}(labels::Array{T<:FloatingPoint,1},features::Array{U<:Real,2},nsubfeatures::Integer,ntrees::Integer,maxlabels,partialsampling) at /home/juser/.julia/v0.3/DecisionTree/src/DecisionTree.jl:415
- build_forest(labels::Array{T,1},features::Array{T,2},nsubfeatures::Integer,ntrees::Integer) at /home/juser/.julia/v0.3/DecisionTree/src/DecisionTree.jl:245
- build_forest(labels::Array{T,1},features::Array{T,2},nsubfeatures::Integer,ntrees::Integer,partialsampling) at /home/juser/.julia/v0.3/DecisionTree/src/DecisionTree.jl:245
"
],
"text/plain": [
"# 5 methods for generic function \"build_forest\":\n",
"build_forest{T<:FloatingPoint,U<:Real}(labels::Array{T<:FloatingPoint,1},features::Array{U<:Real,2},nsubfeatures::Integer,ntrees::Integer) at /home/juser/.julia/v0.3/DecisionTree/src/DecisionTree.jl:415\n",
"build_forest{T<:FloatingPoint,U<:Real}(labels::Array{T<:FloatingPoint,1},features::Array{U<:Real,2},nsubfeatures::Integer,ntrees::Integer,maxlabels) at /home/juser/.julia/v0.3/DecisionTree/src/DecisionTree.jl:415\n",
"build_forest{T<:FloatingPoint,U<:Real}(labels::Array{T<:FloatingPoint,1},features::Array{U<:Real,2},nsubfeatures::Integer,ntrees::Integer,maxlabels,partialsampling) at /home/juser/.julia/v0.3/DecisionTree/src/DecisionTree.jl:415\n",
"build_forest(labels::Array{T,1},features::Array{T,2},nsubfeatures::Integer,ntrees::Integer) at /home/juser/.julia/v0.3/DecisionTree/src/DecisionTree.jl:245\n",
"build_forest(labels::Array{T,1},features::Array{T,2},nsubfeatures::Integer,ntrees::Integer,partialsampling) at /home/juser/.julia/v0.3/DecisionTree/src/DecisionTree.jl:245"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"methods(build_forest)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#Random Forest"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###build_forest parameters are:\n",
"**signals** _array of the signal we want to calculate \n",
"**features** the corresponding feature array that indicates those signals \n",
"**festures used** the number features for the each split or branch of the tree \n",
"**number of trees** trees in the forrest, larger takes longer, but could be more accurate. \n",
"**sampling rate** number lowered from 1.0 to favor minority signals "
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Ensemble of Decision Trees\n",
"Trees: 10\n",
"Avg Leaves: 3674.7\n",
"Avg Depth: 24.3"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model = build_forest(signals,features,int(sqrt(length(features[1,:]))),10,.9)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Apply the algorithm to any 2D Matix of features"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"27765-element Array{Any,1}:\n",
" 7\n",
" 3\n",
" 0\n",
" 3\n",
" 10\n",
" 0\n",
" 0\n",
" 0\n",
" 4\n",
" 7\n",
" 2\n",
" 5\n",
" 3\n",
" ⋮\n",
" 3\n",
" 10\n",
" 0\n",
" 1\n",
" 0\n",
" 0\n",
" 30\n",
" 3\n",
" 0\n",
" 0\n",
" 20\n",
" 7"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"predictions = apply_forest(model,features)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"32x32 Array{Int64,2}:\n",
" 16566 0 5 10 1 1 0 … 0 0 0 0 0 0 0 0 1 0\n",
" 1 290 68 68 16 5 0 0 0 0 0 0 0 0 0 0 0\n",
" 1 4 1383 114 41 7 0 0 0 0 1 0 0 0 0 0 0\n",
" 0 2 87 1856 45 7 2 0 0 0 0 0 0 1 0 0 0\n",
" 1 1 32 95 1129 4 1 0 0 0 1 0 0 1 0 0 0\n",
" 1 0 56 143 46 841 1 … 0 0 0 0 0 0 1 0 0 0\n",
" 1 0 23 55 26 8 287 0 0 0 0 0 0 2 0 0 0\n",
" 1 0 24 66 16 8 0 0 0 0 0 0 0 0 0 0 0\n",
" 0 0 4 16 12 3 1 0 0 0 0 0 0 0 0 0 0\n",
" 0 0 1 6 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 0 0 12 40 18 5 1 … 0 0 0 0 0 0 0 0 0 0\n",
" 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0\n",
" 1 0 2 4 6 1 0 0 0 0 0 0 0 1 0 0 0\n",
" ⋮ ⋮ ⋱ ⋮ ⋮ \n",
" 1 3 7 23 13 6 0 … 0 0 0 1 0 0 3 0 0 0\n",
" 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0\n",
" 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0\n",
" 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0\n",
" 0 0 0 0 1 2 0 … 0 0 0 56 0 0 0 0 0 0\n",
" 0 0 1 1 0 1 0 0 0 0 0 2 0 0 0 0 0\n",
" 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0\n",
" 0 0 13 22 4 3 0 0 0 0 0 0 0 274 0 0 0\n",
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0\n",
" 0 1 7 18 6 4 1 … 0 0 0 0 0 0 0 0 153 0\n",
" 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"Classes: {0,1,2,3,4,5,6,7,8,9 … 22,23,24,25,26,27,28,29,30,60}\n",
"Matrix: \n",
"Accuracy: 0.9280388978930308\n",
"Kappa: 0.8846820611436211"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"confusion_matrix(signals,predictions)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"https://github.com/bensadeghi/DecisionTree.jl/tree/83765089feb5b2d30d72046ab78ca044841c827d \n",
"http://bensadeghi.com/decision-trees-julia/ \n",
"http://appliedpredictivemodeling.com/blog/2013/12/8/28rmc2lv96h8fw8700zm4nl50busep \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.3.9",
"language": "julia",
"name": "julia-0.3"
},
"language_info": {
"name": "julia",
"version": "0.3.9"
}
},
"nbformat": 4,
"nbformat_minor": 0
}