GitHub PullRequestReviewCommentEvent at 2014-09-15 08:38:01
Repository: scikit-learn
Actor: MechCoder
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/17530833","id":17530833,"diff_hunk":"@@ -1416,28 +1429,55 @@ def hinge_loss(y_true, pred_decision, pos_label=None, neg_label=None):\n     array([-2.18...,  2.36...,  0.09...])\n     >>> hinge_loss([-1, 1, 1], pred_decision)  # doctest: +ELLIPSIS\n     0.30...\n-\n+    >>> #Multiclass Hinge Loss Demonstration\n+    >>> X = np.array([[0], [1], [2], [3]])\n+    >>> Y = np.array([[0], [1], [2], [3]])\n+    >>> labels = np.array([0, 1, 2, 3])\n+    >>> est = svm.LinearSVC()\n+    >>> est.fit(X, Y)\n+    LinearSVC(C=1.0, class_weight=None, dual=True, fit_intercept=True,\n+         intercept_scaling=1, loss='l2', max_iter=1000, multi_class='ovr',\n+         penalty='l2', random_state=None, tol=0.0001, verbose=0)\n+    >>> pred_decision = est.decision_function([[-1], [2], [3]])\n+    >>> y_true = [0, 2, 3]\n+    >>> hinge_loss(y_true, pred_decision, labels=labels)  #doctest: +ELLIPSIS\n+    0.97...\n     \"\"\"\n-    # TODO: multi-class hinge-loss\n     check_consistent_length(y_true, pred_decision)\n     y_true = column_or_1d(y_true)\n-    pred_decision = column_or_1d(pred_decision)\n-\n-    # the rest of the code assumes that positive and negative labels\n-    # are encoded as +1 and -1 respectively\n-    lbin = LabelBinarizer(neg_label=-1)\n-    y_true = lbin.fit_transform(y_true)[:, 0]\n-\n-    if len(lbin.classes_) > 2 or (pred_decision.ndim == 2\n-                                  and pred_decision.shape[1] != 1):\n-        raise ValueError(\"Multi-class hinge loss not supported\")\n-    pred_decision = np.ravel(pred_decision)\n-\n-    try:\n-        margin = y_true * pred_decision\n-    except TypeError:\n-        raise TypeError(\"pred_decision should be an array of floats.\")\n+\n+    if (labels is not None and len(labels) > 2) or\\\n+       (len(np.unique(y_true)) > 2):\n+        # Handles Multiclass case\n+        check_X_y(pred_decision, y_true, multi_output=True)","path":"sklearn/metrics/classification.py","position":85,"original_position":85,"commit_id":"0e7e97aef63245c40b4273be8e653c81a65e4959","original_commit_id":"0e7e97aef63245c40b4273be8e653c81a65e4959","user":{"login":"MechCoder","id":1867024,"avatar_url":"https://avatars.githubusercontent.com/u/1867024?v=2","gravatar_id":"92d7b3c4844c27255d0cd305e9f65c67","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":"You can use the returned value of `y_true` and `pred_decision` from `check_X_y`","created_at":"2014-09-15T08:38:01Z","updated_at":"2014-09-15T08:38:01Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/3607#discussion_r17530833","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3607","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/17530833"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/3607#discussion_r17530833"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3607"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3607","id":20525272,"html_url":"https://github.com/scikit-learn/scikit-learn/pull/3607","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/3607.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/3607.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3607","number":3607,"state":"open","locked":false,"title":"Implements Multiclass hinge loss","user":{"login":"SaurabhJha","id":1582386,"avatar_url":"https://avatars.githubusercontent.com/u/1582386?v=2","gravatar_id":"61e5190997041c42240b274492c6d932","url":"https://api.github.com/users/SaurabhJha","html_url":"https://github.com/SaurabhJha","followers_url":"https://api.github.com/users/SaurabhJha/followers","following_url":"https://api.github.com/users/SaurabhJha/following{/other_user}","gists_url":"https://api.github.com/users/SaurabhJha/gists{/gist_id}","starred_url":"https://api.github.com/users/SaurabhJha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SaurabhJha/subscriptions","organizations_url":"https://api.github.com/users/SaurabhJha/orgs","repos_url":"https://api.github.com/users/SaurabhJha/repos","events_url":"https://api.github.com/users/SaurabhJha/events{/privacy}","received_events_url":"https://api.github.com/users/SaurabhJha/received_events","type":"User","site_admin":false},"body":"Implements multiclass hinge loss. Fixes #3451 ","created_at":"2014-08-29T21:47:02Z","updated_at":"2014-09-15T08:38:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d330d28190ef488b8cf6208608372a62cee43b4d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3607/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3607/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/3607/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/0e7e97aef63245c40b4273be8e653c81a65e4959","head":{"label":"SaurabhJha:3451","ref":"3451","sha":"0e7e97aef63245c40b4273be8e653c81a65e4959","user":{"login":"SaurabhJha","id":1582386,"avatar_url":"https://avatars.githubusercontent.com/u/1582386?v=2","gravatar_id":"61e5190997041c42240b274492c6d932","url":"https://api.github.com/users/SaurabhJha","html_url":"https://github.com/SaurabhJha","followers_url":"https://api.github.com/users/SaurabhJha/followers","following_url":"https://api.github.com/users/SaurabhJha/following{/other_user}","gists_url":"https://api.github.com/users/SaurabhJha/gists{/gist_id}","starred_url":"https://api.github.com/users/SaurabhJha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SaurabhJha/subscriptions","organizations_url":"https://api.github.com/users/SaurabhJha/orgs","repos_url":"https://api.github.com/users/SaurabhJha/repos","events_url":"https://api.github.com/users/SaurabhJha/events{/privacy}","received_events_url":"https://api.github.com/users/SaurabhJha/received_events","type":"User","site_admin":false},"repo":{"id":22516469,"name":"scikit-learn","full_name":"SaurabhJha/scikit-learn","owner":{"login":"SaurabhJha","id":1582386,"avatar_url":"https://avatars.githubusercontent.com/u/1582386?v=2","gravatar_id":"61e5190997041c42240b274492c6d932","url":"https://api.github.com/users/SaurabhJha","html_url":"https://github.com/SaurabhJha","followers_url":"https://api.github.com/users/SaurabhJha/followers","following_url":"https://api.github.com/users/SaurabhJha/following{/other_user}","gists_url":"https://api.github.com/users/SaurabhJha/gists{/gist_id}","starred_url":"https://api.github.com/users/SaurabhJha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SaurabhJha/subscriptions","organizations_url":"https://api.github.com/users/SaurabhJha/orgs","repos_url":"https://api.github.com/users/SaurabhJha/repos","events_url":"https://api.github.com/users/SaurabhJha/events{/privacy}","received_events_url":"https://api.github.com/users/SaurabhJha/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/SaurabhJha/scikit-learn","description":"scikit-learn: machine learning in Python","fork":true,"url":"https://api.github.com/repos/SaurabhJha/scikit-learn","forks_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/forks","keys_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/teams","hooks_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/events","assignees_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/tags","blobs_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/subscription","commits_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/issues/comments/{number}","contents_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/merges","archive_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/downloads","issues_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/SaurabhJha/scikit-learn/releases{/id}","created_at":"2014-08-01T15:56:41Z","updated_at":"2014-08-01T15:24:46Z","pushed_at":"2014-09-14T03:57:42Z","git_url":"git://github.com/SaurabhJha/scikit-learn.git","ssh_url":"git@github.com:SaurabhJha/scikit-learn.git","clone_url":"https://github.com/SaurabhJha/scikit-learn.git","svn_url":"https://github.com/SaurabhJha/scikit-learn","homepage":"http://scikit-learn.org","size":53348,"stargazers_count":0,"watchers_count":0,"language":null,"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":"38f5b6c2630bade45dcf85a89c4441b4e0c5f3b6","user":{"login":"scikit-learn","id":365630,"avatar_url":"https://avatars.githubusercontent.com/u/365630?v=2","gravatar_id":"8a6ecb57b119c5a5b3d882d08a909278","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=2","gravatar_id":"8a6ecb57b119c5a5b3d882d08a909278","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}","created_at":"2010-08-17T09:43:38Z","updated_at":"2014-09-15T08:28:51Z","pushed_at":"2014-09-13T14:03:56Z","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":118166,"stargazers_count":4063,"watchers_count":4063,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2178,"mirror_url":null,"open_issues_count":491,"forks":2178,"open_issues":491,"watchers":4063,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3607"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/3607"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3607"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3607/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3607/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/3607/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/0e7e97aef63245c40b4273be8e653c81a65e4959"}}}}