{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/38605369","id":38605369,"diff_hunk":"@@ -803,13 +829,17 @@ private class LogisticAggregator(\n     this\n   }\n \n-  def count: Long = totalCnt\n-\n-  def loss: Double = lossSum / totalCnt\n+  def loss: Double = {\n+    require(weightSum >= 1.0, s\"The effective number of samples should be \" +","path":"mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala","position":221,"original_position":221,"commit_id":"e94bb9559b98f1ae9e58cf88eddc0415a509687e","original_commit_id":"e94bb9559b98f1ae9e58cf88eddc0415a509687e","user":{"login":"dbtsai","id":1134574,"avatar_url":"https://avatars.githubusercontent.com/u/1134574?v=3","gravatar_id":"","url":"https://api.github.com/users/dbtsai","html_url":"https://github.com/dbtsai","followers_url":"https://api.github.com/users/dbtsai/followers","following_url":"https://api.github.com/users/dbtsai/following{/other_user}","gists_url":"https://api.github.com/users/dbtsai/gists{/gist_id}","starred_url":"https://api.github.com/users/dbtsai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbtsai/subscriptions","organizations_url":"https://api.github.com/users/dbtsai/orgs","repos_url":"https://api.github.com/users/dbtsai/repos","events_url":"https://api.github.com/users/dbtsai/events{/privacy}","received_events_url":"https://api.github.com/users/dbtsai/received_events","type":"User","site_admin":false},"body":"@rotationsymmetry  This definition requires sum of weights == 1. I was originally thinking about to use this definition, but that will not be compatible with unbiased version as @mengxr pointed out. What users want may be weight=2 means this instance appears in the training dataset twice. ","created_at":"2015-09-03T01:29:54Z","updated_at":"2015-09-03T01:29:54Z","html_url":"https://github.com/apache/spark/pull/7884#discussion_r38605369","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/7884","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/38605369"},"html":{"href":"https://github.com/apache/spark/pull/7884#discussion_r38605369"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/7884"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/7884","id":41434520,"html_url":"https://github.com/apache/spark/pull/7884","diff_url":"https://github.com/apache/spark/pull/7884.diff","patch_url":"https://github.com/apache/spark/pull/7884.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/7884","number":7884,"state":"open","locked":false,"title":"[SPARK-7685][ML] Apply weights to different samples in Logistic Regression","user":{"login":"dbtsai","id":1134574,"avatar_url":"https://avatars.githubusercontent.com/u/1134574?v=3","gravatar_id":"","url":"https://api.github.com/users/dbtsai","html_url":"https://github.com/dbtsai","followers_url":"https://api.github.com/users/dbtsai/followers","following_url":"https://api.github.com/users/dbtsai/following{/other_user}","gists_url":"https://api.github.com/users/dbtsai/gists{/gist_id}","starred_url":"https://api.github.com/users/dbtsai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbtsai/subscriptions","organizations_url":"https://api.github.com/users/dbtsai/orgs","repos_url":"https://api.github.com/users/dbtsai/repos","events_url":"https://api.github.com/users/dbtsai/events{/privacy}","received_events_url":"https://api.github.com/users/dbtsai/received_events","type":"User","site_admin":false},"body":"In fraud detection dataset, almost all the samples are negative while only couple of them are positive. This type of high imbalanced data will bias the models toward negative resulting poor performance. In python-scikit, they provide a correction allowing users to Over-/undersample the samples of each class according to the given weights. In auto mode, selects weights inversely proportional to class frequencies in the training set. This can be done in a more efficient way by multiplying the weights into loss and gradient instead of doing actual over/undersampling in the training dataset which is very expensive.\r\nhttp://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html\r\nOn the other hand, some of the training data maybe more important like the training samples from tenure users while the training samples from new users maybe less important. We should be able to provide another \"weight: Double\" information in the LabeledPoint to weight them differently in the learning algorithm.\r\n","created_at":"2015-08-03T04:40:54Z","updated_at":"2015-09-03T01:29:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4076f5412fe149029c02c27d26178d98b0e4afd4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/7884/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/7884/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/7884/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/e94bb9559b98f1ae9e58cf88eddc0415a509687e","head":{"label":"dbtsai:SPARK-7685","ref":"SPARK-7685","sha":"e94bb9559b98f1ae9e58cf88eddc0415a509687e","user":{"login":"dbtsai","id":1134574,"avatar_url":"https://avatars.githubusercontent.com/u/1134574?v=3","gravatar_id":"","url":"https://api.github.com/users/dbtsai","html_url":"https://github.com/dbtsai","followers_url":"https://api.github.com/users/dbtsai/followers","following_url":"https://api.github.com/users/dbtsai/following{/other_user}","gists_url":"https://api.github.com/users/dbtsai/gists{/gist_id}","starred_url":"https://api.github.com/users/dbtsai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbtsai/subscriptions","organizations_url":"https://api.github.com/users/dbtsai/orgs","repos_url":"https://api.github.com/users/dbtsai/repos","events_url":"https://api.github.com/users/dbtsai/events{/privacy}","received_events_url":"https://api.github.com/users/dbtsai/received_events","type":"User","site_admin":false},"repo":{"id":34716514,"name":"spark","full_name":"dbtsai/spark","owner":{"login":"dbtsai","id":1134574,"avatar_url":"https://avatars.githubusercontent.com/u/1134574?v=3","gravatar_id":"","url":"https://api.github.com/users/dbtsai","html_url":"https://github.com/dbtsai","followers_url":"https://api.github.com/users/dbtsai/followers","following_url":"https://api.github.com/users/dbtsai/following{/other_user}","gists_url":"https://api.github.com/users/dbtsai/gists{/gist_id}","starred_url":"https://api.github.com/users/dbtsai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbtsai/subscriptions","organizations_url":"https://api.github.com/users/dbtsai/orgs","repos_url":"https://api.github.com/users/dbtsai/repos","events_url":"https://api.github.com/users/dbtsai/events{/privacy}","received_events_url":"https://api.github.com/users/dbtsai/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dbtsai/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/dbtsai/spark","forks_url":"https://api.github.com/repos/dbtsai/spark/forks","keys_url":"https://api.github.com/repos/dbtsai/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dbtsai/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dbtsai/spark/teams","hooks_url":"https://api.github.com/repos/dbtsai/spark/hooks","issue_events_url":"https://api.github.com/repos/dbtsai/spark/issues/events{/number}","events_url":"https://api.github.com/repos/dbtsai/spark/events","assignees_url":"https://api.github.com/repos/dbtsai/spark/assignees{/user}","branches_url":"https://api.github.com/repos/dbtsai/spark/branches{/branch}","tags_url":"https://api.github.com/repos/dbtsai/spark/tags","blobs_url":"https://api.github.com/repos/dbtsai/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dbtsai/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dbtsai/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/dbtsai/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dbtsai/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/dbtsai/spark/languages","stargazers_url":"https://api.github.com/repos/dbtsai/spark/stargazers","contributors_url":"https://api.github.com/repos/dbtsai/spark/contributors","subscribers_url":"https://api.github.com/repos/dbtsai/spark/subscribers","subscription_url":"https://api.github.com/repos/dbtsai/spark/subscription","commits_url":"https://api.github.com/repos/dbtsai/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/dbtsai/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/dbtsai/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/dbtsai/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/dbtsai/spark/contents/{+path}","compare_url":"https://api.github.com/repos/dbtsai/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dbtsai/spark/merges","archive_url":"https://api.github.com/repos/dbtsai/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dbtsai/spark/downloads","issues_url":"https://api.github.com/repos/dbtsai/spark/issues{/number}","pulls_url":"https://api.github.com/repos/dbtsai/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/dbtsai/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/dbtsai/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dbtsai/spark/labels{/name}","releases_url":"https://api.github.com/repos/dbtsai/spark/releases{/id}","created_at":"2015-04-28T07:50:55Z","updated_at":"2015-05-08T18:53:28Z","pushed_at":"2015-09-02T09:00:07Z","git_url":"git://github.com/dbtsai/spark.git","ssh_url":"git@github.com:dbtsai/spark.git","clone_url":"https://github.com/dbtsai/spark.git","svn_url":"https://github.com/dbtsai/spark","homepage":null,"size":120355,"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":"391e6be0ae883f3ea0fab79463eb8b618af79afb","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-09-03T00:44:00Z","pushed_at":"2015-09-03T01:27:27Z","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":1706375,"stargazers_count":5278,"watchers_count":5278,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4852,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":369,"forks":4852,"open_issues":369,"watchers":5278,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/7884"},"html":{"href":"https://github.com/apache/spark/pull/7884"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/7884"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/7884/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/7884/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/7884/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/e94bb9559b98f1ae9e58cf88eddc0415a509687e"}}}}