Skip to content

Commit 9979a94

Browse files
author
Darius Morawiec
committed
Add new templates, examples and tests
1 parent abd0f8b commit 9979a94

36 files changed

+4385
-3930
lines changed

examples/estimator/classifier/AdaBoostClassifier/java/basics_embedded.ipynb

+57-31
Original file line numberDiff line numberDiff line change
@@ -92,36 +92,10 @@
9292
},
9393
{
9494
"cell_type": "code",
95-
"execution_count": 4,
95+
"execution_count": 5,
9696
"metadata": {
9797
"scrolled": false
9898
},
99-
"outputs": [
100-
{
101-
"name": "stdout",
102-
"output_type": "stream",
103-
"text": [
104-
"CPU times: user 2.34 ms, sys: 2.05 ms, total: 4.39 ms\n",
105-
"Wall time: 2.96 ms\n"
106-
]
107-
}
108-
],
109-
"source": [
110-
"%%time\n",
111-
"\n",
112-
"from sklearn_porter import Porter\n",
113-
"\n",
114-
"porter = Porter(clf)\n",
115-
"output = porter.export()\n",
116-
"\n",
117-
"with open('AdaBoostClassifier.java', 'w') as f:\n",
118-
" f.write(output)"
119-
]
120-
},
121-
{
122-
"cell_type": "code",
123-
"execution_count": 6,
124-
"metadata": {},
12599
"outputs": [
126100
{
127101
"name": "stdout",
@@ -386,14 +360,21 @@
386360
" }\n",
387361
" }\n",
388362
"\n",
389-
"}"
363+
"}\n",
364+
"CPU times: user 3.13 ms, sys: 2.24 ms, total: 5.37 ms\n",
365+
"Wall time: 3.6 ms\n"
390366
]
391367
}
392368
],
393369
"source": [
394-
"%%bash\n",
370+
"%%time\n",
395371
"\n",
396-
"cat AdaBoostClassifier.java"
372+
"from sklearn_porter import Porter\n",
373+
"\n",
374+
"porter = Porter(clf)\n",
375+
"output = porter.export()\n",
376+
"\n",
377+
"print(output)"
397378
]
398379
},
399380
{
@@ -403,9 +384,55 @@
403384
"### Run classification in Java:"
404385
]
405386
},
387+
{
388+
"cell_type": "markdown",
389+
"metadata": {},
390+
"source": [
391+
"Save the estimator:"
392+
]
393+
},
394+
{
395+
"cell_type": "code",
396+
"execution_count": 6,
397+
"metadata": {
398+
"collapsed": true
399+
},
400+
"outputs": [],
401+
"source": [
402+
"with open('AdaBoostClassifier.java', 'w') as f:\n",
403+
" f.write(output)"
404+
]
405+
},
406+
{
407+
"cell_type": "markdown",
408+
"metadata": {},
409+
"source": [
410+
"Compiling:"
411+
]
412+
},
406413
{
407414
"cell_type": "code",
408415
"execution_count": 7,
416+
"metadata": {
417+
"collapsed": true
418+
},
419+
"outputs": [],
420+
"source": [
421+
"%%bash\n",
422+
"\n",
423+
"javac -cp . AdaBoostClassifier.java"
424+
]
425+
},
426+
{
427+
"cell_type": "markdown",
428+
"metadata": {},
429+
"source": [
430+
"Prediction:"
431+
]
432+
},
433+
{
434+
"cell_type": "code",
435+
"execution_count": 8,
409436
"metadata": {},
410437
"outputs": [
411438
{
@@ -419,7 +446,6 @@
419446
"source": [
420447
"%%bash\n",
421448
"\n",
422-
"javac -cp . AdaBoostClassifier.java\n",
423449
"java AdaBoostClassifier 1 2 3 4"
424450
]
425451
}

examples/estimator/classifier/AdaBoostClassifier/java/basics_embedded.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
clf.fit(X, y)
1717

1818
porter = Porter(clf)
19-
output = porter.export()
19+
output = porter.export(embed_data=True)
2020
print(output)
2121

2222
"""

examples/estimator/classifier/AdaBoostClassifier/java/basics_imported.ipynb

+64-66
Original file line numberDiff line numberDiff line change
@@ -92,43 +92,10 @@
9292
},
9393
{
9494
"cell_type": "code",
95-
"execution_count": 5,
95+
"execution_count": 4,
9696
"metadata": {
9797
"scrolled": false
9898
},
99-
"outputs": [
100-
{
101-
"name": "stdout",
102-
"output_type": "stream",
103-
"text": [
104-
"CPU times: user 2.34 ms, sys: 1.87 ms, total: 4.21 ms\n",
105-
"Wall time: 2.76 ms\n"
106-
]
107-
}
108-
],
109-
"source": [
110-
"%%time\n",
111-
"\n",
112-
"from sklearn_porter import Porter\n",
113-
"\n",
114-
"porter = Porter(clf)\n",
115-
"output = porter.export(export_data=True)\n",
116-
"\n",
117-
"with open('AdaBoostClassifier.java', 'w') as f:\n",
118-
" f.write(output)"
119-
]
120-
},
121-
{
122-
"cell_type": "markdown",
123-
"metadata": {},
124-
"source": [
125-
"Classifier:"
126-
]
127-
},
128-
{
129-
"cell_type": "code",
130-
"execution_count": 6,
131-
"metadata": {},
13299
"outputs": [
133100
{
134101
"name": "stdout",
@@ -242,7 +209,7 @@
242209
" // Parameters:\n",
243210
" String modelData = args[0];\n",
244211
"\n",
245-
" // Estimators:\n",
212+
" // Estimator:\n",
246213
" AdaBoostClassifier clf = new AdaBoostClassifier(modelData);\n",
247214
"\n",
248215
" // Prediction:\n",
@@ -251,14 +218,21 @@
251218
"\n",
252219
" }\n",
253220
" }\n",
254-
"}"
221+
"}\n",
222+
"CPU times: user 1.73 ms, sys: 1.43 ms, total: 3.16 ms\n",
223+
"Wall time: 2.12 ms\n"
255224
]
256225
}
257226
],
258227
"source": [
259-
"%%bash\n",
228+
"%%time\n",
229+
"\n",
230+
"from sklearn_porter import Porter\n",
231+
"\n",
232+
"porter = Porter(clf)\n",
233+
"output = porter.export(export_data=True)\n",
260234
"\n",
261-
"cat AdaBoostClassifier.java"
235+
"print(output)"
262236
]
263237
},
264238
{
@@ -270,7 +244,7 @@
270244
},
271245
{
272246
"cell_type": "code",
273-
"execution_count": 7,
247+
"execution_count": 5,
274248
"metadata": {},
275249
"outputs": [
276250
{
@@ -291,58 +265,58 @@
291265
"cell_type": "markdown",
292266
"metadata": {},
293267
"source": [
294-
"File size:"
268+
"### Run classification in Java:"
295269
]
296270
},
297271
{
298-
"cell_type": "code",
299-
"execution_count": 8,
272+
"cell_type": "markdown",
300273
"metadata": {},
301-
"outputs": [
302-
{
303-
"name": "stdout",
304-
"output_type": "stream",
305-
"text": [
306-
"4.0K\tdata.json\n"
307-
]
308-
}
309-
],
310274
"source": [
311-
"%%bash\n",
312-
"\n",
313-
"du -h data.json"
275+
"Save the estimator:"
276+
]
277+
},
278+
{
279+
"cell_type": "code",
280+
"execution_count": 6,
281+
"metadata": {
282+
"collapsed": true
283+
},
284+
"outputs": [],
285+
"source": [
286+
"with open('AdaBoostClassifier.java', 'w') as f:\n",
287+
" f.write(output)"
314288
]
315289
},
316290
{
317291
"cell_type": "markdown",
318292
"metadata": {},
319293
"source": [
320-
"### Run classification in Java:"
294+
"Download dependencies:"
321295
]
322296
},
323297
{
324298
"cell_type": "code",
325-
"execution_count": 9,
299+
"execution_count": 7,
326300
"metadata": {},
327301
"outputs": [
328302
{
329303
"name": "stderr",
330304
"output_type": "stream",
331305
"text": [
332-
"--2017-11-24 00:59:42-- http://central.maven.org/maven2/com/google/code/gson/gson/2.8.2/gson-2.8.2.jar\n",
306+
"--2017-11-26 22:27:24-- http://central.maven.org/maven2/com/google/code/gson/gson/2.8.2/gson-2.8.2.jar\n",
333307
"Resolving central.maven.org... 151.101.36.209\n",
334308
"Connecting to central.maven.org|151.101.36.209|:80... connected.\n",
335309
"HTTP request sent, awaiting response... 200 OK\n",
336310
"Length: 232932 (227K) [application/java-archive]\n",
337-
"Saving to: 'gson-2.8.2.jar'\n",
311+
"Saving to: 'gson-2.8.2.jar.1'\n",
338312
"\n",
339-
" 0K .......... .......... .......... .......... .......... 21% 1.78M 0s\n",
340-
" 50K .......... .......... .......... .......... .......... 43% 4.10M 0s\n",
341-
" 100K .......... .......... .......... .......... .......... 65% 3.36M 0s\n",
342-
" 150K .......... .......... .......... .......... .......... 87% 132M 0s\n",
343-
" 200K .......... .......... ....... 100% 32.6M=0.06s\n",
313+
" 0K .......... .......... .......... .......... .......... 21% 1.55M 0s\n",
314+
" 50K .......... .......... .......... .......... .......... 43% 4.48M 0s\n",
315+
" 100K .......... .......... .......... .......... .......... 65% 6.49M 0s\n",
316+
" 150K .......... .......... .......... .......... .......... 87% 6.72M 0s\n",
317+
" 200K .......... .......... ....... 100% 6.03M=0.06s\n",
344318
"\n",
345-
"2017-11-24 00:59:42 (4.04 MB/s) - 'gson-2.8.2.jar' saved [232932/232932]\n",
319+
"2017-11-26 22:27:24 (3.60 MB/s) - 'gson-2.8.2.jar.1' saved [232932/232932]\n",
346320
"\n"
347321
]
348322
}
@@ -353,9 +327,34 @@
353327
"wget http://central.maven.org/maven2/com/google/code/gson/gson/2.8.2/gson-2.8.2.jar"
354328
]
355329
},
330+
{
331+
"cell_type": "markdown",
332+
"metadata": {},
333+
"source": [
334+
"Compiling:"
335+
]
336+
},
337+
{
338+
"cell_type": "code",
339+
"execution_count": 8,
340+
"metadata": {},
341+
"outputs": [],
342+
"source": [
343+
"%%bash\n",
344+
"\n",
345+
"javac -cp .:gson-2.8.2.jar AdaBoostClassifier.java"
346+
]
347+
},
348+
{
349+
"cell_type": "markdown",
350+
"metadata": {},
351+
"source": [
352+
"Prediction:"
353+
]
354+
},
356355
{
357356
"cell_type": "code",
358-
"execution_count": 10,
357+
"execution_count": 9,
359358
"metadata": {},
360359
"outputs": [
361360
{
@@ -369,7 +368,6 @@
369368
"source": [
370369
"%%bash\n",
371370
"\n",
372-
"javac -cp .:gson-2.8.2.jar AdaBoostClassifier.java\n",
373371
"java -cp .:gson-2.8.2.jar AdaBoostClassifier data.json 1 2 3 4"
374372
]
375373
}

0 commit comments

Comments
 (0)