{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/30760088","id":30760088,"diff_hunk":"@@ -0,0 +1,73 @@\n+---\n+layout: global\n+title: Ensembles\n+displayTitle: <a href=\"ml-guide.html\">ML</a> - Ensembles\n+---\n+\n+* Table of contents\n+{:toc}\n+\n+An [ensemble method](http://en.wikipedia.org/wiki/Ensemble_learning)\n+is a learning algorithm which creates a model composed of a set of other base models.\n+ML supports the following ensemble algorithms: [`OneVsRest`](api/scala/index.html#org.apache.spark.ml.classifier.OneVsRest)\n+\n+## OneVsRest\n+\n+[OneVsRest](http://en.wikipedia.org/wiki/Multiclass_classification#One-vs.-rest) is an example of a machine learning reduction for performing multiclass classification given a base classifier that can perform binary classification efficiently.\n+\n+`OneVsRest` is implemented as an `Estimator` takes as base classifier instances of `Classifier` and creates a binary classification problem for each of the k classes. The classifier for class i is trained to predict whether the label is i or not, distinguishing class i from all other classes.\n+\n+Predictions are done by evaluating each binary classifier and the index of the most confident classifier is output as label.\n+\n+### Example\n+\n+The example below demonstrates how to load a\n+[LIBSVM data file](http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/), parse it as an RDD of `LabeledPoint` and perform multiclass classification using `OneVsRest`. The test error is calculated to measure the algorithm accuracy.\n+\n+<div class=\"codetabs\">\n+<div data-lang=\"scala\" markdown=\"1\">\n+{% highlight scala %}\n+import org.apache.spark.ml.classification.{LogisticRegression, OneVsRest}\n+import org.apache.spark.ml.util.MetadataUtils\n+import org.apache.spark.mllib.evaluation.MulticlassMetrics\n+import org.apache.spark.mllib.util.MLUtils\n+import org.apache.spark.sql.{Row, SQLContext}\n+import org.apache.spark.sql.functions._\n+\n+val sqlContext = new SQLContext(sc)\n+import sqlContext.implicits._\n+\n+// parse data into dataframe\n+val data = MLUtils.loadLibSVMFile(sc, \"data/mllib/sample_multiclass_classification_data.txt\")\n+.toDF()\n+.withColumn(\"rnd\", rand(0))\n+\n+val train = data.filter($\"rnd\" < 0.8)\n+val test = data.filter($\"rnd\" >= 0.8)\n+\n+// instantiate multiclass learner and train\n+val ovr = new OneVsRest().setClassifier(new LogisticRegression)\n+\n+val ovrModel = ovr.fit(train)\n+\n+// score model on test data\n+val predictions = ovrModel.transform(test).select(\"prediction\", \"label\")\n+\n+val predictionsRDD = predictions.map {case Row(p: Double, l: Double) => (p, l)}\n+\n+// compute confusion matrix\n+val metrics = new MulticlassMetrics(predictionsRDD)\n+\n+println(metrics.confusionMatrix)\n+\n+// compute the false positive rate per label\n+val predictionColSchema = predictions.schema(\"prediction\")\n+val numClasses = MetadataUtils.getNumClasses(predictionColSchema).get\n+val fprs = Range(0, numClasses).map(p => (p, metrics.falsePositiveRate(p.toDouble)))\n+\n+println(\"label\\tfpr\")\n+\n+println(fprs.map {case (label, fpr) => label + \"\\t\" + fpr}.mkString(\"\\n\"))\n+\n+{% endhighlight %}\n+</div>","path":"docs/ml-ensembles.md","position":73,"original_position":73,"commit_id":"4b7d1a6f49c937a0ab476fd735bfd63ed78e8e6d","original_commit_id":"4b7d1a6f49c937a0ab476fd735bfd63ed78e8e6d","user":{"login":"jkbradley","id":5084283,"avatar_url":"https://avatars.githubusercontent.com/u/5084283?v=3","gravatar_id":"","url":"https://api.github.com/users/jkbradley","html_url":"https://github.com/jkbradley","followers_url":"https://api.github.com/users/jkbradley/followers","following_url":"https://api.github.com/users/jkbradley/following{/other_user}","gists_url":"https://api.github.com/users/jkbradley/gists{/gist_id}","starred_url":"https://api.github.com/users/jkbradley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkbradley/subscriptions","organizations_url":"https://api.github.com/users/jkbradley/orgs","repos_url":"https://api.github.com/users/jkbradley/repos","events_url":"https://api.github.com/users/jkbradley/events{/privacy}","received_events_url":"https://api.github.com/users/jkbradley/received_events","type":"User","site_admin":false},"body":"Missing another ```</div>```","created_at":"2015-05-20T23:24:01Z","updated_at":"2015-05-20T23:24:01Z","html_url":"https://github.com/apache/spark/pull/6296#discussion_r30760088","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/6296","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/30760088"},"html":{"href":"https://github.com/apache/spark/pull/6296#discussion_r30760088"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/6296"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/6296","id":35879951,"html_url":"https://github.com/apache/spark/pull/6296","diff_url":"https://github.com/apache/spark/pull/6296.diff","patch_url":"https://github.com/apache/spark/pull/6296.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/6296","number":6296,"state":"open","locked":false,"title":"[SPARK-7574][ml][doc] User guide for OneVsRest","user":{"login":"harsha2010","id":271956,"avatar_url":"https://avatars.githubusercontent.com/u/271956?v=3","gravatar_id":"","url":"https://api.github.com/users/harsha2010","html_url":"https://github.com/harsha2010","followers_url":"https://api.github.com/users/harsha2010/followers","following_url":"https://api.github.com/users/harsha2010/following{/other_user}","gists_url":"https://api.github.com/users/harsha2010/gists{/gist_id}","starred_url":"https://api.github.com/users/harsha2010/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harsha2010/subscriptions","organizations_url":"https://api.github.com/users/harsha2010/orgs","repos_url":"https://api.github.com/users/harsha2010/repos","events_url":"https://api.github.com/users/harsha2010/events{/privacy}","received_events_url":"https://api.github.com/users/harsha2010/received_events","type":"User","site_admin":false},"body":"Including Iris Dataset (after shuffling and relabeling 3 -> 0 to confirm to 0 -> numClasses-1 labeling). Could not find an existing dataset in data/mllib for multiclass classification.","created_at":"2015-05-20T21:49:37Z","updated_at":"2015-05-20T23:24:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"329f10ae0f3326a5252874beb9d1f6f7b78df51f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/6296/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/6296/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/6296/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/4b7d1a6f49c937a0ab476fd735bfd63ed78e8e6d","head":{"label":"harsha2010:SPARK-7574","ref":"SPARK-7574","sha":"4b7d1a6f49c937a0ab476fd735bfd63ed78e8e6d","user":{"login":"harsha2010","id":271956,"avatar_url":"https://avatars.githubusercontent.com/u/271956?v=3","gravatar_id":"","url":"https://api.github.com/users/harsha2010","html_url":"https://github.com/harsha2010","followers_url":"https://api.github.com/users/harsha2010/followers","following_url":"https://api.github.com/users/harsha2010/following{/other_user}","gists_url":"https://api.github.com/users/harsha2010/gists{/gist_id}","starred_url":"https://api.github.com/users/harsha2010/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harsha2010/subscriptions","organizations_url":"https://api.github.com/users/harsha2010/orgs","repos_url":"https://api.github.com/users/harsha2010/repos","events_url":"https://api.github.com/users/harsha2010/events{/privacy}","received_events_url":"https://api.github.com/users/harsha2010/received_events","type":"User","site_admin":false},"repo":{"id":34759855,"name":"spark","full_name":"harsha2010/spark","owner":{"login":"harsha2010","id":271956,"avatar_url":"https://avatars.githubusercontent.com/u/271956?v=3","gravatar_id":"","url":"https://api.github.com/users/harsha2010","html_url":"https://github.com/harsha2010","followers_url":"https://api.github.com/users/harsha2010/followers","following_url":"https://api.github.com/users/harsha2010/following{/other_user}","gists_url":"https://api.github.com/users/harsha2010/gists{/gist_id}","starred_url":"https://api.github.com/users/harsha2010/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harsha2010/subscriptions","organizations_url":"https://api.github.com/users/harsha2010/orgs","repos_url":"https://api.github.com/users/harsha2010/repos","events_url":"https://api.github.com/users/harsha2010/events{/privacy}","received_events_url":"https://api.github.com/users/harsha2010/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/harsha2010/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/harsha2010/spark","forks_url":"https://api.github.com/repos/harsha2010/spark/forks","keys_url":"https://api.github.com/repos/harsha2010/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/harsha2010/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/harsha2010/spark/teams","hooks_url":"https://api.github.com/repos/harsha2010/spark/hooks","issue_events_url":"https://api.github.com/repos/harsha2010/spark/issues/events{/number}","events_url":"https://api.github.com/repos/harsha2010/spark/events","assignees_url":"https://api.github.com/repos/harsha2010/spark/assignees{/user}","branches_url":"https://api.github.com/repos/harsha2010/spark/branches{/branch}","tags_url":"https://api.github.com/repos/harsha2010/spark/tags","blobs_url":"https://api.github.com/repos/harsha2010/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/harsha2010/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/harsha2010/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/harsha2010/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/harsha2010/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/harsha2010/spark/languages","stargazers_url":"https://api.github.com/repos/harsha2010/spark/stargazers","contributors_url":"https://api.github.com/repos/harsha2010/spark/contributors","subscribers_url":"https://api.github.com/repos/harsha2010/spark/subscribers","subscription_url":"https://api.github.com/repos/harsha2010/spark/subscription","commits_url":"https://api.github.com/repos/harsha2010/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/harsha2010/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/harsha2010/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/harsha2010/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/harsha2010/spark/contents/{+path}","compare_url":"https://api.github.com/repos/harsha2010/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/harsha2010/spark/merges","archive_url":"https://api.github.com/repos/harsha2010/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/harsha2010/spark/downloads","issues_url":"https://api.github.com/repos/harsha2010/spark/issues{/number}","pulls_url":"https://api.github.com/repos/harsha2010/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/harsha2010/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/harsha2010/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/harsha2010/spark/labels{/name}","releases_url":"https://api.github.com/repos/harsha2010/spark/releases{/id}","created_at":"2015-04-28T22:43:49Z","updated_at":"2015-04-28T22:44:09Z","pushed_at":"2015-05-20T22:04:06Z","git_url":"git://github.com/harsha2010/spark.git","ssh_url":"git@github.com:harsha2010/spark.git","clone_url":"https://github.com/harsha2010/spark.git","svn_url":"https://github.com/harsha2010/spark","homepage":null,"size":107090,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"6338c40da61de045485c51aa11a5b1e425d22144","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-05-20T22:07:39Z","pushed_at":"2015-05-20T23:21:44Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":1701952,"stargazers_count":4035,"watchers_count":4035,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3542,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":311,"forks":3542,"open_issues":311,"watchers":4035,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/6296"},"html":{"href":"https://github.com/apache/spark/pull/6296"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/6296"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/6296/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/6296/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/6296/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/4b7d1a6f49c937a0ab476fd735bfd63ed78e8e6d"}}}}