GitHub PullRequestReviewCommentEvent at 2014-07-17 07:02:22
Repository: scikit-learn
Actor: arjoly
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/15043373","id":15043373,"diff_hunk":"@@ -133,6 +135,168 @@ def _check_clf_targets(y_true, y_pred):\n     return y_type, y_true, y_pred\n \n \n+class _SparseMultilabelHelper(object):\n+    \"\"\"Helper for aggregates over sparse binary label indicators\n+    \"\"\"\n+\n+    def __init__(self, y_true, y_pred, sample_weight=None):\n+        self.y_true = csr_matrix(y_true)\n+        self.y_pred = csr_matrix(y_pred)\n+        self.shape = y_true.shape\n+        self.sample_weight = sample_weight\n+\n+    def count_union(self, axis=None):\n+        return self._count_nnz(self.y_true + self.y_pred, axis,\n+                               self.sample_weight)\n+\n+    def count_intersection(self, axis=None):\n+        return self._count_nnz(self.y_true.multiply(self.y_pred), axis,\n+                               self.sample_weight)\n+\n+    def count_difference(self, axis=None):\n+        # pending availability of != or xor\n+        return self.count_union(axis) - self.count_intersection(axis)\n+\n+    def count_true(self, axis=None):\n+        return self._count_nnz(self.y_true, axis, self.sample_weight)\n+\n+    def count_pred(self, axis=None):\n+        return self._count_nnz(self.y_pred, axis, self.sample_weight)\n+\n+    @staticmethod\n+    def _count_nnz(X, axis=None, sample_weight=None):\n+        if axis is None:\n+            if sample_weight is None:\n+                return X.nnz\n+            else:\n+                return (np.diff(X.indptr) * sample_weight).sum()\n+        elif axis == 1:\n+            out = np.diff(X.indptr)\n+            if sample_weight is None:\n+                return out\n+            return out * sample_weight\n+        elif axis == 0:\n+            if sample_weight is None:\n+                return np.bincount(X.indices, minlength=X.shape[1])\n+            else:\n+                weights = np.repeat(sample_weight, np.diff(X.indptr))\n+                return np.bincount(X.indices, minlength=X.shape[1],\n+                                   weights=weights)\n+        raise ValueError('Unsupported axis: {0}'.format(axis))\n+\n+\n+class _DenseMultilabelHelper(object):\n+    \"\"\"Helper for aggregates over dense binary label indicators\n+    \"\"\"\n+\n+    def __init__(self, y_true, y_pred, sample_weight=None):\n+        self.y_true = y_true == 1\n+        self.y_pred = y_pred == 1\n+        self.shape = y_true.shape\n+        self.sample_weight = sample_weight\n+\n+    def _weight(self, X):","path":"sklearn/metrics/metrics.py","position":99,"original_position":92,"commit_id":"813cfbd263f11c3b050b7086c4943ab183bdde9c","original_commit_id":"6508bd7948f87dccd3f1a3caf2f0ea2c3cf34908","user":{"login":"arjoly","id":1274722,"avatar_url":"https://avatars.githubusercontent.com/u/1274722?","gravatar_id":"9fb38ab677ea6f73bb07faa43b0677f9","url":"https://api.github.com/users/arjoly","html_url":"https://github.com/arjoly","followers_url":"https://api.github.com/users/arjoly/followers","following_url":"https://api.github.com/users/arjoly/following{/other_user}","gists_url":"https://api.github.com/users/arjoly/gists{/gist_id}","starred_url":"https://api.github.com/users/arjoly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arjoly/subscriptions","organizations_url":"https://api.github.com/users/arjoly/orgs","repos_url":"https://api.github.com/users/arjoly/repos","events_url":"https://api.github.com/users/arjoly/events{/privacy}","received_events_url":"https://api.github.com/users/arjoly/received_events","type":"User","site_admin":false},"body":"What do you think of `Y` to recall that this is an output matrix?","created_at":"2014-07-17T07:02:22Z","updated_at":"2014-07-17T07:02:22Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/3395#discussion_r15043373","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3395","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/15043373"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/3395#discussion_r15043373"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3395"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3395","id":18466131,"html_url":"https://github.com/scikit-learn/scikit-learn/pull/3395","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/3395.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/3395.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3395","number":3395,"state":"open","title":"[MRG] Sparse multilabel target support in metrics","user":{"login":"jnothman","id":78827,"avatar_url":"https://avatars.githubusercontent.com/u/78827?","gravatar_id":"7677b43f6049d41c64cc332c381028ac","url":"https://api.github.com/users/jnothman","html_url":"https://github.com/jnothman","followers_url":"https://api.github.com/users/jnothman/followers","following_url":"https://api.github.com/users/jnothman/following{/other_user}","gists_url":"https://api.github.com/users/jnothman/gists{/gist_id}","starred_url":"https://api.github.com/users/jnothman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jnothman/subscriptions","organizations_url":"https://api.github.com/users/jnothman/orgs","repos_url":"https://api.github.com/users/jnothman/repos","events_url":"https://api.github.com/users/jnothman/events{/privacy}","received_events_url":"https://api.github.com/users/jnothman/received_events","type":"User","site_admin":false},"body":"This introduces a series of helper classes that abstract away aggregation over multilabel structures. This enables efficient calculation in sparse and dense binary indicator matrices, while maintaining support for the deprecated sequences format.","created_at":"2014-07-16T13:02:18Z","updated_at":"2014-07-17T07:02:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c1867a935cde4be2131c1a6b2bfed7fec0eda5fd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3395/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3395/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/3395/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/813cfbd263f11c3b050b7086c4943ab183bdde9c","head":{"label":"jnothman:sparse_multi_metrics","ref":"sparse_multi_metrics","sha":"813cfbd263f11c3b050b7086c4943ab183bdde9c","user":{"login":"jnothman","id":78827,"avatar_url":"https://avatars.githubusercontent.com/u/78827?","gravatar_id":"7677b43f6049d41c64cc332c381028ac","url":"https://api.github.com/users/jnothman","html_url":"https://github.com/jnothman","followers_url":"https://api.github.com/users/jnothman/followers","following_url":"https://api.github.com/users/jnothman/following{/other_user}","gists_url":"https://api.github.com/users/jnothman/gists{/gist_id}","starred_url":"https://api.github.com/users/jnothman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jnothman/subscriptions","organizations_url":"https://api.github.com/users/jnothman/orgs","repos_url":"https://api.github.com/users/jnothman/repos","events_url":"https://api.github.com/users/jnothman/events{/privacy}","received_events_url":"https://api.github.com/users/jnothman/received_events","type":"User","site_admin":false},"repo":{"id":8691611,"name":"scikit-learn","full_name":"jnothman/scikit-learn","owner":{"login":"jnothman","id":78827,"avatar_url":"https://avatars.githubusercontent.com/u/78827?","gravatar_id":"7677b43f6049d41c64cc332c381028ac","url":"https://api.github.com/users/jnothman","html_url":"https://github.com/jnothman","followers_url":"https://api.github.com/users/jnothman/followers","following_url":"https://api.github.com/users/jnothman/following{/other_user}","gists_url":"https://api.github.com/users/jnothman/gists{/gist_id}","starred_url":"https://api.github.com/users/jnothman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jnothman/subscriptions","organizations_url":"https://api.github.com/users/jnothman/orgs","repos_url":"https://api.github.com/users/jnothman/repos","events_url":"https://api.github.com/users/jnothman/events{/privacy}","received_events_url":"https://api.github.com/users/jnothman/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jnothman/scikit-learn","description":"scikit-learn: machine learning in Python","fork":true,"url":"https://api.github.com/repos/jnothman/scikit-learn","forks_url":"https://api.github.com/repos/jnothman/scikit-learn/forks","keys_url":"https://api.github.com/repos/jnothman/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jnothman/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jnothman/scikit-learn/teams","hooks_url":"https://api.github.com/repos/jnothman/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/jnothman/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/jnothman/scikit-learn/events","assignees_url":"https://api.github.com/repos/jnothman/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/jnothman/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/jnothman/scikit-learn/tags","blobs_url":"https://api.github.com/repos/jnothman/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jnothman/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jnothman/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/jnothman/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jnothman/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/jnothman/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/jnothman/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/jnothman/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/jnothman/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/jnothman/scikit-learn/subscription","commits_url":"https://api.github.com/repos/jnothman/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/jnothman/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/jnothman/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/jnothman/scikit-learn/issues/comments/{number}","contents_url":"https://api.github.com/repos/jnothman/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/jnothman/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jnothman/scikit-learn/merges","archive_url":"https://api.github.com/repos/jnothman/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jnothman/scikit-learn/downloads","issues_url":"https://api.github.com/repos/jnothman/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/jnothman/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/jnothman/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/jnothman/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jnothman/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/jnothman/scikit-learn/releases{/id}","created_at":"2013-03-10T21:10:51Z","updated_at":"2014-06-25T07:16:07Z","pushed_at":"2014-07-17T02:58:09Z","git_url":"git://github.com/jnothman/scikit-learn.git","ssh_url":"git@github.com:jnothman/scikit-learn.git","clone_url":"https://github.com/jnothman/scikit-learn.git","svn_url":"https://github.com/jnothman/scikit-learn","homepage":"http://scikit-learn.org","size":56556,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"2e7ef3c9a944bea17b52f185c756a2a63087b5ad","user":{"login":"scikit-learn","id":365630,"avatar_url":"https://avatars.githubusercontent.com/u/365630?","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?","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-07-17T03:53:14Z","pushed_at":"2014-07-16T16:58:05Z","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":109471,"stargazers_count":3625,"watchers_count":3625,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":1910,"mirror_url":null,"open_issues_count":476,"forks":1910,"open_issues":476,"watchers":3625,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3395"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/3395"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3395"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/3395/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/3395/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/3395/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/813cfbd263f11c3b050b7086c4943ab183bdde9c"}}}}