Skip to content

Commit

Permalink
extend multiclass nb
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurabh7 committed Mar 1, 2014
1 parent 6f5f9a0 commit de52f93
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions doc/ipython-notebooks/multiclass/multiclass_reduction.ipynb
Expand Up @@ -458,6 +458,56 @@
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Expanding on the idea of creating a generic multiclass machine and then assigning a particular multiclass strategy and a base binary machine, one can also use the [KernelMulticlassMachine](http://www.shogun-toolbox.org/doc/en/current/classshogun_1_1CKernelMulticlassMachine.html) with a kernel of choice.\n",
"\n",
"Here we will use a [GaussianKernel](http://www.shogun-toolbox.org/doc/en/3.0.0/classshogun_1_1CGaussianKernel.html) with LibSVM as the classifer.\n",
"All we have to do is define a new helper evaluate function with the features defined as in the above examples."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def evaluate(strategy):\n",
" from modshogun import KernelMulticlassMachine, LibSVM, GaussianKernel\n",
" width=2.1\n",
" epsilon=1e-5\n",
" \n",
" kernel=GaussianKernel(feats_train, feats_train, width)\n",
" \n",
" classifier = LibSVM()\n",
"\tclassifier.set_epsilon(epsilon)\n",
"\n",
" mc_machine = KernelMulticlassMachine(strategy, kernel, classifier, lab_train)\n",
"\n",
" t_begin = time.clock()\n",
" mc_machine.train()\n",
" t_train = time.clock() - t_begin\n",
"\n",
" t_begin = time.clock()\n",
" pred_test = mc_machine.apply_multiclass(feats_test)\n",
" t_test = time.clock() - t_begin\n",
"\n",
" evaluator = MulticlassAccuracy()\n",
" acc = evaluator.evaluate(pred_test, lab_test)\n",
"\n",
" print \"training time: %.4f\" % t_train\n",
" print \"testing time: %.4f\" % t_test\n",
" print \"accuracy: %.4f\" % acc\n",
"\n",
"print \"\\nOne-vs-Rest\"\n",
"print \"=\"*60\n",
"evaluate(MulticlassOneVsRestStrategy())\n",
"\n"
],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
Expand Down

0 comments on commit de52f93

Please sign in to comment.