{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/60971502","id":60971502,"diff_hunk":"@@ -62,6 +65,76 @@ abstract class Classifier[\n   def setRawPredictionCol(value: String): E = set(rawPredictionCol, value).asInstanceOf[E]\n \n   // TODO: defaultEvaluator (follow-up PR)\n+\n+  /**\n+   * Extract [[labelCol]] and [[featuresCol]] from the given dataset,\n+   * and put it in an RDD with strong types.\n+   * @throws SparkException  if any label is not an integer >= 0\n+   */\n+  override protected def extractLabeledPoints(dataset: Dataset[_]): RDD[LabeledPoint] = {\n+    dataset.select(col($(labelCol)).cast(DoubleType), col($(featuresCol))).rdd.map {\n+      case Row(label: Double, features: Vector) =>\n+        require(label % 1 == 0 && label >= 0, s\"Classifier was given dataset with invalid label\" +\n+          s\" $label.  Labels must be integers in range [0, 1, ..., numClasses-1]\")\n+        LabeledPoint(label, features)\n+    }\n+  }\n+\n+  /**\n+   * Get the number of classes.  This looks in column metadata first, and if that is missing,\n+   * then this assumes classes are indexed 0,1,...,numClasses-1 and computes numClasses\n+   * by finding the maximum label value.\n+   *\n+   * Label validation (ensuring all labels are integers >= 0) needs to be handled elsewhere,\n+   * such as in [[extractLabeledPoints()]].\n+   *\n+   * @param dataset  Dataset which contains a column [[labelCol]]\n+   * @param maxNumClasses  Maximum number of classes allowed when inferred from data.  If numClasses\n+   *                       is specified in the metadata, then maxNumClasses is ignored.\n+   * @return  number of classes\n+   * @throws IllegalArgumentException  if metadata does not specify numClasses, and the\n+   *                                   actual numClasses exceeds maxNumClasses\n+   */\n+  protected def getNumClasses(dataset: Dataset[_], maxNumClasses: Int = 1000): Int = {\n+    MetadataUtils.getNumClasses(dataset.schema($(labelCol))) match {\n+      case Some(n: Int) => n\n+      case None =>","path":"mllib/src/main/scala/org/apache/spark/ml/classification/Classifier.scala","position":58,"original_position":58,"commit_id":"657faef37dfd097e6f63998b165d70c006414a86","original_commit_id":"94e206f0e98f0a2d398de71f808008a9acb711f1","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":"Logging a warning seems reasonable to me.  We could also decrease maxNumClasses to force users to do indexing in iffier situations.","created_at":"2016-04-25T19:18:16Z","updated_at":"2016-04-25T19:18:16Z","html_url":"https://github.com/apache/spark/pull/12663#discussion_r60971502","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/12663","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/60971502"},"html":{"href":"https://github.com/apache/spark/pull/12663#discussion_r60971502"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/12663"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/12663","id":67759206,"html_url":"https://github.com/apache/spark/pull/12663","diff_url":"https://github.com/apache/spark/pull/12663.diff","patch_url":"https://github.com/apache/spark/pull/12663.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/12663","number":12663,"state":"open","locked":false,"title":"[SPARK-14862][ML] Updated Classifiers to not require labelCol metadata","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":"## What changes were proposed in this pull request?\r\n\r\nUpdated Classifier, DecisionTreeClassifier, RandomForestClassifier, GBTClassifier to not require input column metadata.\r\n* They first check for metadata.\r\n* If numClasses is not specified in metadata, they identify the largest label value (up to a limit).\r\n\r\nThis functionality is implemented in a new Classifier.getNumClasses method.\r\n\r\nAlso\r\n* Updated Classifier.extractLabeledPoints to (a) check label values and (b) include a second version which takes a numClasses value for validity checking.\r\n\r\n## How was this patch tested?\r\n\r\n* Unit tests in ClassifierSuite for helper methods\r\n* Unit tests for DecisionTreeClassifier, RandomForestClassifier, GBTClassifier with toy datasets lacking label metadata","created_at":"2016-04-25T17:42:09Z","updated_at":"2016-04-25T19:18:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b9e36694b7a661484786624bbd4fa4090c54008c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/12663/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/12663/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/12663/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/657faef37dfd097e6f63998b165d70c006414a86","head":{"label":"jkbradley:trees-no-metadata","ref":"trees-no-metadata","sha":"657faef37dfd097e6f63998b165d70c006414a86","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},"repo":{"id":19877817,"name":"spark","full_name":"jkbradley/spark","owner":{"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},"private":false,"html_url":"https://github.com/jkbradley/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/jkbradley/spark","forks_url":"https://api.github.com/repos/jkbradley/spark/forks","keys_url":"https://api.github.com/repos/jkbradley/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jkbradley/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jkbradley/spark/teams","hooks_url":"https://api.github.com/repos/jkbradley/spark/hooks","issue_events_url":"https://api.github.com/repos/jkbradley/spark/issues/events{/number}","events_url":"https://api.github.com/repos/jkbradley/spark/events","assignees_url":"https://api.github.com/repos/jkbradley/spark/assignees{/user}","branches_url":"https://api.github.com/repos/jkbradley/spark/branches{/branch}","tags_url":"https://api.github.com/repos/jkbradley/spark/tags","blobs_url":"https://api.github.com/repos/jkbradley/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jkbradley/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jkbradley/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/jkbradley/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jkbradley/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/jkbradley/spark/languages","stargazers_url":"https://api.github.com/repos/jkbradley/spark/stargazers","contributors_url":"https://api.github.com/repos/jkbradley/spark/contributors","subscribers_url":"https://api.github.com/repos/jkbradley/spark/subscribers","subscription_url":"https://api.github.com/repos/jkbradley/spark/subscription","commits_url":"https://api.github.com/repos/jkbradley/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/jkbradley/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/jkbradley/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/jkbradley/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/jkbradley/spark/contents/{+path}","compare_url":"https://api.github.com/repos/jkbradley/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jkbradley/spark/merges","archive_url":"https://api.github.com/repos/jkbradley/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jkbradley/spark/downloads","issues_url":"https://api.github.com/repos/jkbradley/spark/issues{/number}","pulls_url":"https://api.github.com/repos/jkbradley/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/jkbradley/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/jkbradley/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jkbradley/spark/labels{/name}","releases_url":"https://api.github.com/repos/jkbradley/spark/releases{/id}","deployments_url":"https://api.github.com/repos/jkbradley/spark/deployments","created_at":"2014-05-17T03:51:41Z","updated_at":"2016-01-11T22:41:59Z","pushed_at":"2016-04-25T19:02:34Z","git_url":"git://github.com/jkbradley/spark.git","ssh_url":"git@github.com:jkbradley/spark.git","clone_url":"https://github.com/jkbradley/spark.git","svn_url":"https://github.com/jkbradley/spark","homepage":null,"size":167035,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":7,"forks":3,"open_issues":7,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"a680562a6f87a03a00f71bad1c424267ae75c641","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}","deployments_url":"https://api.github.com/repos/apache/spark/deployments","created_at":"2014-02-25T08:00:08Z","updated_at":"2016-04-25T17:33:20Z","pushed_at":"2016-04-25T19:09:36Z","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":470217,"stargazers_count":8284,"watchers_count":8284,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7669,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":425,"forks":7669,"open_issues":425,"watchers":8284,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/12663"},"html":{"href":"https://github.com/apache/spark/pull/12663"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/12663"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/12663/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/12663/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/12663/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/657faef37dfd097e6f63998b165d70c006414a86"}}}}