{"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/76150055","id":76150055,"diff_hunk":"@@ -1597,36 +1602,53 @@ def log_loss(y_true, y_pred, eps=1e-15, normalize=True, sample_weight=None):\n     The logarithm used is the natural logarithm (base-e).\n     \"\"\"\n     lb = LabelBinarizer()\n-    T = lb.fit_transform(y_true)\n-    if T.shape[1] == 1:\n-        T = np.append(1 - T, T, axis=1)\n \n+    if labels is not None:\n+        lb.fit(labels)\n+    else:\n+        lb.fit(y_true)\n+\n+    if labels is None and len(lb.classes_) == 1:\n+        raise ValueError('y_true has only one label. Please provide '\n+                         'the true labels explicitly through the labels '\n+                         'argument.')\n+    if labels is not None and len(lb.classes_) == 1:\n+        raise ValueError('labels should have more than one unique label.')\n+\n+    transformed_labels = lb.transform(y_true)\n+\n+    if transformed_labels.shape[1] == 1:\n+        transformed_labels = np.append(1 - transformed_labels,\n+                                       transformed_labels, axis=1)\n     y_pred = check_array(y_pred, ensure_2d=False)\n+\n     # Clipping\n-    Y = np.clip(y_pred, eps, 1 - eps)\n+    y_pred = np.clip(y_pred, eps, 1 - eps)\n \n     # This happens in cases when elements in y_pred have type \"str\".\n-    if not isinstance(Y, np.ndarray):\n+    if not isinstance(y_pred, np.ndarray):\n         raise ValueError(\"y_pred should be an array of floats.\")\n \n     # If y_pred is of single dimension, assume y_true to be binary\n     # and then check.\n-    if Y.ndim == 1:\n-        Y = Y[:, np.newaxis]\n-    if Y.shape[1] == 1:\n-        Y = np.append(1 - Y, Y, axis=1)\n+    if y_pred.ndim == 1:\n+        y_pred = y_pred[:, np.newaxis]\n+    if y_pred.shape[1] == 1:\n+        y_pred = np.append(1 - y_pred, y_pred, axis=1)\n \n     # Check if dimensions are consistent.\n-    check_consistent_length(T, Y)\n-    T = check_array(T)\n-    Y = check_array(Y)\n-    if T.shape[1] != Y.shape[1]:\n+    check_consistent_length(transformed_labels, y_pred)\n+    transformed_labels = check_array(transformed_labels)\n+    y_pred = check_array(y_pred)\n+    if transformed_labels.shape[1] != y_pred.shape[1]:\n         raise ValueError(\"y_true and y_pred have different number of classes \"\n-                         \"%d, %d\" % (T.shape[1], Y.shape[1]))\n+                         \"%d, %d. Please provide the true labels explicitly \"\n+                         \"through the labels argument\" %\n+                         (transformed_labels.shape[1], y_pred.shape[1]))\n \n     # Renormalize\n-    Y /= Y.sum(axis=1)[:, np.newaxis]\n-    loss = -(T * np.log(Y)).sum(axis=1)\n+    y_pred /= y_pred.sum(axis=1)[:, np.newaxis]","path":"sklearn/metrics/classification.py","position":90,"original_position":86,"commit_id":"eeaac5d719440cf08cab7957ed7e5fc6394040d8","original_commit_id":"31d489a398fc57b565c44baf0eb102baedd5aa00","user":{"login":"MechCoder","id":1867024,"avatar_url":"https://avatars.githubusercontent.com/u/1867024?v=3","gravatar_id":"","url":"https://api.github.com/users/MechCoder","html_url":"https://github.com/MechCoder","followers_url":"https://api.github.com/users/MechCoder/followers","following_url":"https://api.github.com/users/MechCoder/following{/other_user}","gists_url":"https://api.github.com/users/MechCoder/gists{/gist_id}","starred_url":"https://api.github.com/users/MechCoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MechCoder/subscriptions","organizations_url":"https://api.github.com/users/MechCoder/orgs","repos_url":"https://api.github.com/users/MechCoder/repos","events_url":"https://api.github.com/users/MechCoder/events{/privacy}","received_events_url":"https://api.github.com/users/MechCoder/received_events","type":"User","site_admin":false},"body":"Ooh yeah, ofc sorry..","created_at":"2016-08-24T22:18:43Z","updated_at":"2016-08-24T22:18:43Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/7239#discussion_r76150055","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7239","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/76150055"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/7239#discussion_r76150055"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7239"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7239","id":82614410,"html_url":"https://github.com/scikit-learn/scikit-learn/pull/7239","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/7239.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/7239.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7239","number":7239,"state":"open","locked":false,"title":"[MRG] Fix log loss bug","user":{"login":"nelson-liu","id":7272031,"avatar_url":"https://avatars.githubusercontent.com/u/7272031?v=3","gravatar_id":"","url":"https://api.github.com/users/nelson-liu","html_url":"https://github.com/nelson-liu","followers_url":"https://api.github.com/users/nelson-liu/followers","following_url":"https://api.github.com/users/nelson-liu/following{/other_user}","gists_url":"https://api.github.com/users/nelson-liu/gists{/gist_id}","starred_url":"https://api.github.com/users/nelson-liu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nelson-liu/subscriptions","organizations_url":"https://api.github.com/users/nelson-liu/orgs","repos_url":"https://api.github.com/users/nelson-liu/repos","events_url":"https://api.github.com/users/nelson-liu/events{/privacy}","received_events_url":"https://api.github.com/users/nelson-liu/received_events","type":"User","site_admin":false},"body":"#### Reference Issue\r\noriginal PRs at https://github.com/scikit-learn/scikit-learn/pull/6714 and #7166 .\r\nFixes:\r\nmetrics.log_loss fails when any classes are missing in y_true #4033\r\nFix a bug, the result is wrong when use sklearn.metrics.log_loss with one class, #4546\r\nLog_loss is calculated incorrectly when only 1 class present #6703\r\n\r\n#### What does this implement/fix? Explain your changes.\r\nThis PR is a cherrypicked, rebased, and squashed version of #7166. I addressed the comments in there, namely by renaming the single-letter variables, adding another `ValueError` saying that labels should have more than one unique label  if `len(lb.classes_) == 1` and `labels is not None`, and removing a commented out code block. \r\n\r\n#### Any other comments?\r\n@MechCoder @amueller anything else that needs to be done?\r\n","created_at":"2016-08-24T20:46:45Z","updated_at":"2016-08-24T22:18:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f6a28e2e99dde868476cad6b2272d7f56ee50394","assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/milestones/18","html_url":"https://github.com/scikit-learn/scikit-learn/milestones/0.18","labels_url":"https://api.github.com/repos/scikit-learn/scikit-learn/milestones/18/labels","id":1314892,"number":18,"title":"0.18","description":"","creator":{"login":"amueller","id":449558,"avatar_url":"https://avatars.githubusercontent.com/u/449558?v=3","gravatar_id":"","url":"https://api.github.com/users/amueller","html_url":"https://github.com/amueller","followers_url":"https://api.github.com/users/amueller/followers","following_url":"https://api.github.com/users/amueller/following{/other_user}","gists_url":"https://api.github.com/users/amueller/gists{/gist_id}","starred_url":"https://api.github.com/users/amueller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amueller/subscriptions","organizations_url":"https://api.github.com/users/amueller/orgs","repos_url":"https://api.github.com/users/amueller/repos","events_url":"https://api.github.com/users/amueller/events{/privacy}","received_events_url":"https://api.github.com/users/amueller/received_events","type":"User","site_admin":false},"open_issues":66,"closed_issues":34,"state":"open","created_at":"2015-09-20T02:17:00Z","updated_at":"2016-08-24T21:02:29Z","due_on":"2016-02-29T08:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7239/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7239/comments","review_comment_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7239/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/eeaac5d719440cf08cab7957ed7e5fc6394040d8","head":{"label":"nelson-liu:fix_log_loss_bug","ref":"fix_log_loss_bug","sha":"eeaac5d719440cf08cab7957ed7e5fc6394040d8","user":{"login":"nelson-liu","id":7272031,"avatar_url":"https://avatars.githubusercontent.com/u/7272031?v=3","gravatar_id":"","url":"https://api.github.com/users/nelson-liu","html_url":"https://github.com/nelson-liu","followers_url":"https://api.github.com/users/nelson-liu/followers","following_url":"https://api.github.com/users/nelson-liu/following{/other_user}","gists_url":"https://api.github.com/users/nelson-liu/gists{/gist_id}","starred_url":"https://api.github.com/users/nelson-liu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nelson-liu/subscriptions","organizations_url":"https://api.github.com/users/nelson-liu/orgs","repos_url":"https://api.github.com/users/nelson-liu/repos","events_url":"https://api.github.com/users/nelson-liu/events{/privacy}","received_events_url":"https://api.github.com/users/nelson-liu/received_events","type":"User","site_admin":false},"repo":{"id":46840245,"name":"scikit-learn","full_name":"nelson-liu/scikit-learn","owner":{"login":"nelson-liu","id":7272031,"avatar_url":"https://avatars.githubusercontent.com/u/7272031?v=3","gravatar_id":"","url":"https://api.github.com/users/nelson-liu","html_url":"https://github.com/nelson-liu","followers_url":"https://api.github.com/users/nelson-liu/followers","following_url":"https://api.github.com/users/nelson-liu/following{/other_user}","gists_url":"https://api.github.com/users/nelson-liu/gists{/gist_id}","starred_url":"https://api.github.com/users/nelson-liu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nelson-liu/subscriptions","organizations_url":"https://api.github.com/users/nelson-liu/orgs","repos_url":"https://api.github.com/users/nelson-liu/repos","events_url":"https://api.github.com/users/nelson-liu/events{/privacy}","received_events_url":"https://api.github.com/users/nelson-liu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nelson-liu/scikit-learn","description":"scikit-learn: machine learning in Python","fork":true,"url":"https://api.github.com/repos/nelson-liu/scikit-learn","forks_url":"https://api.github.com/repos/nelson-liu/scikit-learn/forks","keys_url":"https://api.github.com/repos/nelson-liu/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nelson-liu/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nelson-liu/scikit-learn/teams","hooks_url":"https://api.github.com/repos/nelson-liu/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/nelson-liu/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/nelson-liu/scikit-learn/events","assignees_url":"https://api.github.com/repos/nelson-liu/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/nelson-liu/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/nelson-liu/scikit-learn/tags","blobs_url":"https://api.github.com/repos/nelson-liu/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nelson-liu/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nelson-liu/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/nelson-liu/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nelson-liu/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/nelson-liu/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/nelson-liu/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/nelson-liu/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/nelson-liu/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/nelson-liu/scikit-learn/subscription","commits_url":"https://api.github.com/repos/nelson-liu/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/nelson-liu/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/nelson-liu/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/nelson-liu/scikit-learn/issues/comments{/number}","contents_url":"https://api.github.com/repos/nelson-liu/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/nelson-liu/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nelson-liu/scikit-learn/merges","archive_url":"https://api.github.com/repos/nelson-liu/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nelson-liu/scikit-learn/downloads","issues_url":"https://api.github.com/repos/nelson-liu/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/nelson-liu/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/nelson-liu/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/nelson-liu/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nelson-liu/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/nelson-liu/scikit-learn/releases{/id}","deployments_url":"https://api.github.com/repos/nelson-liu/scikit-learn/deployments","created_at":"2015-11-25T05:44:49Z","updated_at":"2016-01-11T20:26:31Z","pushed_at":"2016-08-24T21:49:20Z","git_url":"git://github.com/nelson-liu/scikit-learn.git","ssh_url":"git@github.com:nelson-liu/scikit-learn.git","clone_url":"https://github.com/nelson-liu/scikit-learn.git","svn_url":"https://github.com/nelson-liu/scikit-learn","homepage":"http://scikit-learn.org","size":73739,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"scikit-learn:master","ref":"master","sha":"234d25677d2929e058f339661a27c8d22fb47bf6","user":{"login":"scikit-learn","id":365630,"avatar_url":"https://avatars.githubusercontent.com/u/365630?v=3","gravatar_id":"","url":"https://api.github.com/users/scikit-learn","html_url":"https://github.com/scikit-learn","followers_url":"https://api.github.com/users/scikit-learn/followers","following_url":"https://api.github.com/users/scikit-learn/following{/other_user}","gists_url":"https://api.github.com/users/scikit-learn/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-learn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-learn/subscriptions","organizations_url":"https://api.github.com/users/scikit-learn/orgs","repos_url":"https://api.github.com/users/scikit-learn/repos","events_url":"https://api.github.com/users/scikit-learn/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-learn/received_events","type":"Organization","site_admin":false},"repo":{"id":843222,"name":"scikit-learn","full_name":"scikit-learn/scikit-learn","owner":{"login":"scikit-learn","id":365630,"avatar_url":"https://avatars.githubusercontent.com/u/365630?v=3","gravatar_id":"","url":"https://api.github.com/users/scikit-learn","html_url":"https://github.com/scikit-learn","followers_url":"https://api.github.com/users/scikit-learn/followers","following_url":"https://api.github.com/users/scikit-learn/following{/other_user}","gists_url":"https://api.github.com/users/scikit-learn/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-learn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-learn/subscriptions","organizations_url":"https://api.github.com/users/scikit-learn/orgs","repos_url":"https://api.github.com/users/scikit-learn/repos","events_url":"https://api.github.com/users/scikit-learn/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-learn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scikit-learn/scikit-learn","description":"scikit-learn: machine learning in Python","fork":false,"url":"https://api.github.com/repos/scikit-learn/scikit-learn","forks_url":"https://api.github.com/repos/scikit-learn/scikit-learn/forks","keys_url":"https://api.github.com/repos/scikit-learn/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scikit-learn/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scikit-learn/scikit-learn/teams","hooks_url":"https://api.github.com/repos/scikit-learn/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/scikit-learn/scikit-learn/events","assignees_url":"https://api.github.com/repos/scikit-learn/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/scikit-learn/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/scikit-learn/scikit-learn/tags","blobs_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/scikit-learn/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/scikit-learn/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/scikit-learn/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/scikit-learn/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/scikit-learn/scikit-learn/subscription","commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/comments{/number}","contents_url":"https://api.github.com/repos/scikit-learn/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/scikit-learn/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scikit-learn/scikit-learn/merges","archive_url":"https://api.github.com/repos/scikit-learn/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scikit-learn/scikit-learn/downloads","issues_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/scikit-learn/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/scikit-learn/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scikit-learn/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/scikit-learn/scikit-learn/releases{/id}","deployments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/deployments","created_at":"2010-08-17T09:43:38Z","updated_at":"2016-08-24T21:50:51Z","pushed_at":"2016-08-24T21:49:26Z","git_url":"git://github.com/scikit-learn/scikit-learn.git","ssh_url":"git@github.com:scikit-learn/scikit-learn.git","clone_url":"https://github.com/scikit-learn/scikit-learn.git","svn_url":"https://github.com/scikit-learn/scikit-learn","homepage":"http://scikit-learn.org","size":122631,"stargazers_count":12979,"watchers_count":12979,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7512,"mirror_url":null,"open_issues_count":1258,"forks":7512,"open_issues":1258,"watchers":12979,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7239"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/7239"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7239"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7239/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7239/comments"},"review_comment":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7239/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/eeaac5d719440cf08cab7957ed7e5fc6394040d8"}}}}
{"actor":{"display_login":"MechCoder"}}