{"id":172,"date":"2017-02-13T17:58:39","date_gmt":"2017-02-13T17:58:39","guid":{"rendered":"http:\/\/sag.art.uniroma2.it\/kelp_wordpress\/?page_id=172"},"modified":"2017-04-06T15:54:02","modified_gmt":"2017-04-06T15:54:02","slug":"hello-kernel-learning","status":"publish","type":"page","link":"http:\/\/www.kelp-ml.org\/?page_id=172","title":{"rendered":"Hello (kernel) Learning!"},"content":{"rendered":"<p>A second example that we consider is again a classification task, but this time with a kernelized version of the Passive Aggressive algorithm (<a href=\"http:\/\/www.kelp-ml.org\/kelp-javadoc\/current-version\/it\/uniroma2\/sag\/kelp\/learningalgorithm\/classification\/passiveaggressive\/KernelizedPassiveAggressiveClassification.html\" target=\"_blank\">KernelizedPassiveAggressiveClassification<\/a>). The full code of this example can be found in the <a title=\"GitHub\" href=\"https:\/\/github.com\" target=\"_blank\">GitHub<\/a> repository <a title=\"kelp-full repository\" href=\"https:\/\/github.com\/SAG-KeLP\/kelp-full\" target=\"_blank\">kelp-full<\/a>, in particular in the source file <em><a href=\"https:\/\/github.com\/SAG-KeLP\/kelp-full\/blob\/master\/src\/main\/java\/it\/uniroma2\/sag\/kelp\/examples\/main\/HelloKernelLearning.java\" target=\"_blank\">HelloKernelLearning.java<\/a><\/em>.<\/p>\n<p>The dataset here used is again the <a title=\"SvmLight\" href=\"http:\/\/svmlight.joachims.org\" target=\"_blank\">svmlight<\/a> page dataset, in the KeLP format.<br \/>\nAs for the previous example, the dataset is composed by:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/SAG-KeLP\/kelp-full\/blob\/master\/src\/main\/resources\/hellolearning\/train.klp\">Training set<\/a> (2000 examples, 1000 of class &#8220;+1&#8221; (positive), and 1000 of class &#8220;-1&#8221; (negative))<\/li>\n<li><a href=\"https:\/\/github.com\/SAG-KeLP\/kelp-full\/blob\/master\/src\/main\/resources\/hellolearning\/test.klp\">Test set<\/a>\u00a0(600 examples, 300 of class &#8220;+1&#8221; (positive), and 300 of class &#8220;-1&#8221; (negative))<\/li>\n<\/ul>\n<p>Again, loading the dataset is simply a call to KeLP methods:<\/p>\n<pre class=\"lang:java decode:true\" title=\"Loaddataset\">\/\/ Read a dataset into a trainingSet variable\r\nSimpleDataset trainingSet = new SimpleDataset();\r\ntrainingSet.populate(\"src\/main\/resources\/hellolearning\/train.klp\");\r\n\/\/ Read a dataset into a test variable\r\nSimpleDataset testSet = new SimpleDataset();\r\ntestSet.populate(\"src\/main\/resources\/hellolearning\/test.klp\");\r\n\/\/ define the positive class\r\nStringLabel positiveClass = new StringLabel(\"+1\");<\/pre>\n<p>Using a kernel function within <strong>KeLP<\/strong>\u00a0is very simple: it is sufficient to declare a kernel function, the representation on which it will operate and tell the algorithm the it must use a kernel function to compute similarity scores.<\/p>\n<p>For example, if we want to use a <a href=\"http:\/\/www.kelp-ml.org\/kelp-javadoc\/current-version\/it\/uniroma2\/sag\/kelp\/kernel\/standard\/PolynomialKernel.html\" target=\"_blank\">Polynomial<\/a> kernel on top of a linear kernel, it is sufficient to do as following:<\/p>\n<pre class=\"lang:java decode:true\" title=\"classify\">\/\/ instantiate a passive aggressive algorithm\r\nKernelizedPassiveAggressive kPA = new KernelizedPassiveAggressive();\r\n\/\/ indicate to the learner what is the positive class\r\nkPA.setLabel(positiveClass);\r\n\/\/ set an aggressiveness parameter\r\nkPA.setAggressiveness(0.01f);\r\n\/\/ use the first (and only here) representation\r\nKernel linear = new LinearKernel(\"0\");\r\n\/\/ Normalize the linear kernel\r\nNormalizationKernel normalizedKernel = new NormalizationKernel(linear);\r\n\/\/ Apply a Polynomial kernel on the score (normalized) computed by the linear kernel\r\nKernel polyKernel = new PolynomialKernel(2f, normalizedKernel);\r\n\/\/ tell the algorithm that the kernel we want to use in learning is the polynomial kernel\r\nkPA.setKernel(polyKernel);<\/pre>\n<p>The rest of the Java code is very similar to the one of the <a href=\"http:\/\/www.kelp-ml.org\/?page_id=171\" target=\"_blank\">Hello (linear) Learning<\/a> example.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A second example that we consider is again a classification task, but this time with a kernelized version of the Passive Aggressive algorithm (KernelizedPassiveAggressiveClassification). The full code of this example can be found in the GitHub repository kelp-full, in particular in the source file HelloKernelLearning.java. The dataset here used is again the svmlight page dataset, <a href=\"http:\/\/www.kelp-ml.org\/?page_id=172\" rel=\"nofollow\"><span class=\"sr-only\">Read more about Hello (kernel) Learning!<\/span>[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":27,"menu_order":8,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages\/172"}],"collection":[{"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=172"}],"version-history":[{"count":10,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages\/172\/revisions"}],"predecessor-version":[{"id":1014,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages\/172\/revisions\/1014"}],"up":[{"embeddable":true,"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=\/wp\/v2\/pages\/27"}],"wp:attachment":[{"href":"http:\/\/www.kelp-ml.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}