Skip to content

Commit

Permalink
Add new templates, examples and tests for the GaussianNB classifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Darius Morawiec committed Dec 2, 2017
1 parent 3ed7609 commit b68c5df
Show file tree
Hide file tree
Showing 12 changed files with 616 additions and 16 deletions.
86 changes: 81 additions & 5 deletions examples/estimator/classifier/GaussianNB/java/basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {
"scrolled": false
},
Expand Down Expand Up @@ -137,9 +137,9 @@
" }\n",
"\n",
" // Parameters:\n",
" double[] priors = {0.33333333333333331, 0.33333333333333331, 0.33333333333333331};\n",
" double[][] sigmas = {{0.12176400309242481, 0.14227600309242491, 0.029504003092424898, 0.011264003092424885}, {0.26110400309242499, 0.096500003092424902, 0.21640000309242502, 0.038324003092424869}, {0.39625600309242481, 0.10192400309242496, 0.29849600309242508, 0.073924003092424875}};\n",
" double[][] thetas = {{5.0059999999999993, 3.4180000000000006, 1.464, 0.24399999999999991}, {5.9359999999999999, 2.7700000000000005, 4.2599999999999998, 1.3259999999999998}, {6.5879999999999983, 2.9739999999999998, 5.5519999999999996, 2.0259999999999998}};\n",
" double[] priors = {0.333333333333, 0.333333333333, 0.333333333333};\n",
" double[][] sigmas = {{0.121764003092, 0.142276003092, 0.0295040030924, 0.0112640030924}, {0.261104003092, 0.0965000030924, 0.216400003092, 0.0383240030924}, {0.396256003092, 0.101924003092, 0.298496003092, 0.0739240030924}};\n",
" double[][] thetas = {{5.006, 3.418, 1.464, 0.244}, {5.936, 2.77, 4.26, 1.326}, {6.588, 2.974, 5.552, 2.026}};\n",
"\n",
" // Prediction:\n",
" GaussianNB clf = new GaussianNB(priors, sigmas, thetas);\n",
Expand All @@ -148,18 +148,94 @@
"\n",
" }\n",
" }\n",
"}\n"
"}\n",
"CPU times: user 1.06 ms, sys: 777 µs, total: 1.83 ms\n",
"Wall time: 1.15 ms\n"
]
}
],
"source": [
"%%time\n",
"\n",
"from sklearn_porter import Porter\n",
"\n",
"porter = Porter(clf)\n",
"output = porter.export()\n",
"\n",
"print(output)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Run classification in Java:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Save the transpiled estimator:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"with open('GaussianNB.java', 'w') as f:\n",
" f.write(output)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Compiling:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%%bash\n",
"\n",
"javac -cp . GaussianNB.java"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Prediction:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2\n"
]
}
],
"source": [
"%%bash\n",
"\n",
"java -cp . GaussianNB 1 2 3 4"
]
}
],
"metadata": {
Expand Down
Loading

0 comments on commit b68c5df

Please sign in to comment.