{"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/23094673","id":23094673,"diff_hunk":"@@ -523,33 +526,52 @@ def predict(self, X):\n         y : numpy array of shape [n_samples]\n             Predicted multi-class targets.\n         \"\"\"\n+        Y = self.decision_function(X)\n+        return self.classes_[Y.argmax(axis=1)]\n+\n+    def decision_function(self, X):\n+        \"\"\"Decision function for the OneVsOneClassifier.\n+\n+        The decision values for the samples are computed by adding the \n+        normalized sum of pair-wise classification confidence levels to the\n+        votes in order to disambiguate between the decision values when the\n+        votes for all the classes are equal leading to a tie.\n+\n+        Parameters\n+        ----------\n+        X : array-like, shape = [n_samples, n_features]\n+\n+        Returns\n+        -------\n+        Y : array-like, shape = [n_samples, n_classes]\n+        \"\"\"\n         check_is_fitted(self, 'estimators_')\n+\n         n_samples = X.shape[0]\n         n_classes = self.classes_.shape[0]\n         votes = np.zeros((n_samples, n_classes))\n-        scores = np.zeros((n_samples, n_classes))\n+        sum_of_confidences = np.zeros((n_samples, n_classes))","path":"sklearn/multiclass.py","position":90,"original_position":90,"commit_id":"37c58eeabf77b7580bac72db5608f6311d5e87f0","original_commit_id":"37c58eeabf77b7580bac72db5608f6311d5e87f0","user":{"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},"body":"I'm not super confident about that naming but alright ;)","created_at":"2015-01-16T17:24:53Z","updated_at":"2015-01-16T17:24:53Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/3891#discussion_r23094673","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3891","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/23094673"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/3891#discussion_r23094673"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3891"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3891","id":25118185,"html_url":"https://github.com/scikit-learn/scikit-learn/pull/3891","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/3891.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/3891.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3891","number":3891,"state":"open","locked":false,"title":"[MRG+2.5] Add decision_function for OneVsOneClassifier.","user":{"login":"ragv","id":9487348,"avatar_url":"https://avatars.githubusercontent.com/u/9487348?v=3","gravatar_id":"","url":"https://api.github.com/users/ragv","html_url":"https://github.com/ragv","followers_url":"https://api.github.com/users/ragv/followers","following_url":"https://api.github.com/users/ragv/following{/other_user}","gists_url":"https://api.github.com/users/ragv/gists{/gist_id}","starred_url":"https://api.github.com/users/ragv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ragv/subscriptions","organizations_url":"https://api.github.com/users/ragv/orgs","repos_url":"https://api.github.com/users/ragv/repos","events_url":"https://api.github.com/users/ragv/events{/privacy}","received_events_url":"https://api.github.com/users/ragv/received_events","type":"User","site_admin":false},"body":"Adding `decision_function` support for the `OneVsOneClassifier`.\r\n\r\nThis is based off of #1548 and addresses #1523.\r\n\r\n- [x] Implement the `decision_function` for `OneVsOneClassifier` \r\n\r\ndecision_function returns `votes + scores * (0.4 / max(|scores.max(axis=None)|, |scores.min(axis=None)|))`\r\n\r\nAs a corner case, when both max and min are same, it simply returns `votes`.\r\n\r\n- [x] Add tests for ovo decision function\r\n* Tests `decision_function(X).argmax(axis=1) == predict(X)`\r\n* Tests `decision_function(X).shape == (n_samples, n_classes)`\r\n* Tests `np.round(decision_function(X)) == separately_computed_votes`\r\n* Tests `computed_scores = (decision_function(X) - np.round(decision_function(X)) ) * upscale_factor_derived_from_computed_scores `\r\n\r\n- [x] Incorporate the `decision_function` output in `test_ovo_ties`\r\n`ovo_ties` test requires `votes` to assert tie and `scores` to assert if the prediction breaks ties using aggregated decision scores. Both `votes` and `scores` ( individual ) were separately computed till now. These are modified to use `decision_function`\r\n* `votes = round(decision_values)`\r\n* `scaled_aggregated_scores = decision_values - votes`\r\n\r\n@arjoly, @amueller, @mblondel  Pl. review when you find time!","created_at":"2014-11-26T22:28:28Z","updated_at":"2015-01-16T17:24:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"862c50301a700085cdc3eb9c41f64d5b5615e21b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3891/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3891/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/3891/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/37c58eeabf77b7580bac72db5608f6311d5e87f0","head":{"label":"ragv:decision_function_ovo_1523","ref":"decision_function_ovo_1523","sha":"37c58eeabf77b7580bac72db5608f6311d5e87f0","user":{"login":"ragv","id":9487348,"avatar_url":"https://avatars.githubusercontent.com/u/9487348?v=3","gravatar_id":"","url":"https://api.github.com/users/ragv","html_url":"https://github.com/ragv","followers_url":"https://api.github.com/users/ragv/followers","following_url":"https://api.github.com/users/ragv/following{/other_user}","gists_url":"https://api.github.com/users/ragv/gists{/gist_id}","starred_url":"https://api.github.com/users/ragv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ragv/subscriptions","organizations_url":"https://api.github.com/users/ragv/orgs","repos_url":"https://api.github.com/users/ragv/repos","events_url":"https://api.github.com/users/ragv/events{/privacy}","received_events_url":"https://api.github.com/users/ragv/received_events","type":"User","site_admin":false},"repo":{"id":26038110,"name":"scikit-learn","full_name":"ragv/scikit-learn","owner":{"login":"ragv","id":9487348,"avatar_url":"https://avatars.githubusercontent.com/u/9487348?v=3","gravatar_id":"","url":"https://api.github.com/users/ragv","html_url":"https://github.com/ragv","followers_url":"https://api.github.com/users/ragv/followers","following_url":"https://api.github.com/users/ragv/following{/other_user}","gists_url":"https://api.github.com/users/ragv/gists{/gist_id}","starred_url":"https://api.github.com/users/ragv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ragv/subscriptions","organizations_url":"https://api.github.com/users/ragv/orgs","repos_url":"https://api.github.com/users/ragv/repos","events_url":"https://api.github.com/users/ragv/events{/privacy}","received_events_url":"https://api.github.com/users/ragv/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ragv/scikit-learn","description":"scikit-learn: machine learning in Python","fork":true,"url":"https://api.github.com/repos/ragv/scikit-learn","forks_url":"https://api.github.com/repos/ragv/scikit-learn/forks","keys_url":"https://api.github.com/repos/ragv/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ragv/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ragv/scikit-learn/teams","hooks_url":"https://api.github.com/repos/ragv/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/ragv/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/ragv/scikit-learn/events","assignees_url":"https://api.github.com/repos/ragv/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/ragv/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/ragv/scikit-learn/tags","blobs_url":"https://api.github.com/repos/ragv/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ragv/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ragv/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/ragv/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ragv/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/ragv/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/ragv/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/ragv/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/ragv/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/ragv/scikit-learn/subscription","commits_url":"https://api.github.com/repos/ragv/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/ragv/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/ragv/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/ragv/scikit-learn/issues/comments/{number}","contents_url":"https://api.github.com/repos/ragv/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/ragv/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ragv/scikit-learn/merges","archive_url":"https://api.github.com/repos/ragv/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ragv/scikit-learn/downloads","issues_url":"https://api.github.com/repos/ragv/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/ragv/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/ragv/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/ragv/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ragv/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/ragv/scikit-learn/releases{/id}","created_at":"2014-11-01T00:56:31Z","updated_at":"2015-01-16T15:08:40Z","pushed_at":"2015-01-16T15:16:10Z","git_url":"git://github.com/ragv/scikit-learn.git","ssh_url":"git@github.com:ragv/scikit-learn.git","clone_url":"https://github.com/ragv/scikit-learn.git","svn_url":"https://github.com/ragv/scikit-learn","homepage":"http://scikit-learn.org","size":59868,"stargazers_count":0,"watchers_count":0,"language":"C","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":"407aa33b162db43d052eb662ba639fe83fbda0cb","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}","created_at":"2010-08-17T09:43:38Z","updated_at":"2015-01-16T16:57:12Z","pushed_at":"2015-01-16T16:57:12Z","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":108703,"stargazers_count":4847,"watchers_count":4847,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2791,"mirror_url":null,"open_issues_count":562,"forks":2791,"open_issues":562,"watchers":4847,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3891"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/3891"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3891"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3891/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3891/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/3891/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/37c58eeabf77b7580bac72db5608f6311d5e87f0"}}}}