{"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/62205864","id":62205864,"diff_hunk":"@@ -558,53 +589,160 @@ def _fit(self, X, y, labels, parameter_iterable):\n           for train, test in cv.split(X, y, labels))\n \n         # Out is a list of triplet: score, estimator, n_test_samples\n-        n_fits = len(out)\n+        self.n_fits_ = len(out)\n \n-        scores = list()\n-        grid_scores = list()\n-        for grid_start in range(0, n_fits, n_splits):\n-            n_test_samples = 0\n-            score = 0\n-            all_scores = []\n-            for this_score, this_n_test_samples, _, parameters in \\\n-                    out[grid_start:grid_start + n_splits]:\n-                all_scores.append(this_score)\n+        self.n_candidates_ = self.n_fits_ // n_splits\n+        self.n_parameters_ = len(self.parameter_names_)\n+\n+        res_shape = (self.n_candidates_,)\n+\n+        # Lets not initite this everytime and reuse the same array.\n+        all_test_scores = np.empty((n_splits,), dtype=np.float64)\n+\n+        metric = self.metric_name_\n+\n+        search_results = dict()\n+\n+        for param in self.parameter_names_:\n+            # One column to record the values of each parameter\n+            search_results[\"param_%s\" % param] = (\n+                np.ma.masked_all(res_shape, dtype=object))\n+\n+        # Make a column for each split of each metric\n+        for split_i in range(n_splits):\n+            search_results[\"%s_test_split_%s\" % (metric, split_i)] = (\n+                np.empty(res_shape, dtype=np.float64))\n+        search_results[\"%s_test_mean\" % metric] = np.empty(res_shape,\n+                                                           dtype=np.float64)\n+        search_results[\"%s_test_std\" % metric] = np.empty(res_shape,\n+                                                          dtype=np.float64)\n+        search_results[\"%s_test_rank\" % metric] = np.empty(res_shape,\n+                                                           dtype=int)\n+\n+        for fit_i, grid_start in enumerate(range(0, self.n_fits_, n_splits)):\n+            n_test_samples_total = 0\n+            mean_test_score = 0\n+\n+            for split_i, (test_score_i, n_test_samples_i, _, parameters) in \\\n+                    enumerate(out[grid_start:grid_start + n_splits]):\n+                # Record the score/n_test_samples for the i-th split\n+                # of the current parameter setting candidate.\n                 if self.iid:\n-                    this_score *= this_n_test_samples\n-                    n_test_samples += this_n_test_samples\n-                score += this_score\n+                    test_score_i *= n_test_samples_i\n+                    n_test_samples_total += n_test_samples_i\n+\n+                all_test_scores[split_i] = test_score_i\n+                mean_test_score += test_score_i","path":"sklearn/model_selection/_search.py","position":155,"original_position":155,"commit_id":"b4920fc3bd4f865ec045278caf71a1658c32d818","original_commit_id":"b4920fc3bd4f865ec045278caf71a1658c32d818","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":"In fact, it seems to me the outer loop can also be vectorized.","created_at":"2016-05-05T15:42:13Z","updated_at":"2016-05-05T15:42:13Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/6697#discussion_r62205864","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6697","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/62205864"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/6697#discussion_r62205864"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6697"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6697","id":67549035,"html_url":"https://github.com/scikit-learn/scikit-learn/pull/6697","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/6697.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/6697.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6697","number":6697,"state":"open","locked":false,"title":"[WIP] ENH Restructure grid_scores_ into more efficient data structure","user":{"login":"rvraghav93","id":9487348,"avatar_url":"https://avatars.githubusercontent.com/u/9487348?v=3","gravatar_id":"","url":"https://api.github.com/users/rvraghav93","html_url":"https://github.com/rvraghav93","followers_url":"https://api.github.com/users/rvraghav93/followers","following_url":"https://api.github.com/users/rvraghav93/following{/other_user}","gists_url":"https://api.github.com/users/rvraghav93/gists{/gist_id}","starred_url":"https://api.github.com/users/rvraghav93/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rvraghav93/subscriptions","organizations_url":"https://api.github.com/users/rvraghav93/orgs","repos_url":"https://api.github.com/users/rvraghav93/repos","events_url":"https://api.github.com/users/rvraghav93/events{/privacy}","received_events_url":"https://api.github.com/users/rvraghav93/received_events","type":"User","site_admin":false},"body":"Overrides/Fixes #6686, #1034, #1787, #1768\r\n\r\nAlso related #1742, #1020\r\n\r\nTangentially related #1850, #1837, #2759\r\n\r\n- [x] Restructure `grid_scores_` into a more efficient/usable data structure.\r\n- [ ] Nice plot examples\r\n- [ ] Tests\r\n- [ ] Doc\r\n- [ ] Whatsnew\r\n\r\nInitial reviews welcome!\r\n\r\n[The sandbox notebook](https://github.com/rvraghav93/multiple_metric_grid_search_sandbox/blob/master/multiple_metric_grid_search_sandbox.ipynb)\r\n\r\n@amueller @vene @jnothman @agramfort @GaelVaroquaux @mblondel @hlin117 @ogrisel ","created_at":"2016-04-22T17:54:43Z","updated_at":"2016-05-05T15:42:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"00a6b421528e9824c73f88d633413aae67be19a2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6697/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6697/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/6697/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/b4920fc3bd4f865ec045278caf71a1658c32d818","head":{"label":"rvraghav93:multiple_metric_grid_search","ref":"multiple_metric_grid_search","sha":"b4920fc3bd4f865ec045278caf71a1658c32d818","user":{"login":"rvraghav93","id":9487348,"avatar_url":"https://avatars.githubusercontent.com/u/9487348?v=3","gravatar_id":"","url":"https://api.github.com/users/rvraghav93","html_url":"https://github.com/rvraghav93","followers_url":"https://api.github.com/users/rvraghav93/followers","following_url":"https://api.github.com/users/rvraghav93/following{/other_user}","gists_url":"https://api.github.com/users/rvraghav93/gists{/gist_id}","starred_url":"https://api.github.com/users/rvraghav93/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rvraghav93/subscriptions","organizations_url":"https://api.github.com/users/rvraghav93/orgs","repos_url":"https://api.github.com/users/rvraghav93/repos","events_url":"https://api.github.com/users/rvraghav93/events{/privacy}","received_events_url":"https://api.github.com/users/rvraghav93/received_events","type":"User","site_admin":false},"repo":{"id":26038110,"name":"scikit-learn","full_name":"rvraghav93/scikit-learn","owner":{"login":"rvraghav93","id":9487348,"avatar_url":"https://avatars.githubusercontent.com/u/9487348?v=3","gravatar_id":"","url":"https://api.github.com/users/rvraghav93","html_url":"https://github.com/rvraghav93","followers_url":"https://api.github.com/users/rvraghav93/followers","following_url":"https://api.github.com/users/rvraghav93/following{/other_user}","gists_url":"https://api.github.com/users/rvraghav93/gists{/gist_id}","starred_url":"https://api.github.com/users/rvraghav93/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rvraghav93/subscriptions","organizations_url":"https://api.github.com/users/rvraghav93/orgs","repos_url":"https://api.github.com/users/rvraghav93/repos","events_url":"https://api.github.com/users/rvraghav93/events{/privacy}","received_events_url":"https://api.github.com/users/rvraghav93/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rvraghav93/scikit-learn","description":"scikit-learn: machine learning in Python","fork":true,"url":"https://api.github.com/repos/rvraghav93/scikit-learn","forks_url":"https://api.github.com/repos/rvraghav93/scikit-learn/forks","keys_url":"https://api.github.com/repos/rvraghav93/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rvraghav93/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rvraghav93/scikit-learn/teams","hooks_url":"https://api.github.com/repos/rvraghav93/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/rvraghav93/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/rvraghav93/scikit-learn/events","assignees_url":"https://api.github.com/repos/rvraghav93/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/rvraghav93/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/rvraghav93/scikit-learn/tags","blobs_url":"https://api.github.com/repos/rvraghav93/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rvraghav93/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rvraghav93/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/rvraghav93/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rvraghav93/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/rvraghav93/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/rvraghav93/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/rvraghav93/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/rvraghav93/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/rvraghav93/scikit-learn/subscription","commits_url":"https://api.github.com/repos/rvraghav93/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/rvraghav93/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/rvraghav93/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/rvraghav93/scikit-learn/issues/comments{/number}","contents_url":"https://api.github.com/repos/rvraghav93/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/rvraghav93/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rvraghav93/scikit-learn/merges","archive_url":"https://api.github.com/repos/rvraghav93/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rvraghav93/scikit-learn/downloads","issues_url":"https://api.github.com/repos/rvraghav93/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/rvraghav93/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/rvraghav93/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/rvraghav93/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rvraghav93/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/rvraghav93/scikit-learn/releases{/id}","deployments_url":"https://api.github.com/repos/rvraghav93/scikit-learn/deployments","created_at":"2014-11-01T00:56:31Z","updated_at":"2016-04-27T18:29:41Z","pushed_at":"2016-05-03T15:32:30Z","git_url":"git://github.com/rvraghav93/scikit-learn.git","ssh_url":"git@github.com:rvraghav93/scikit-learn.git","clone_url":"https://github.com/rvraghav93/scikit-learn.git","svn_url":"https://github.com/rvraghav93/scikit-learn","homepage":"http://scikit-learn.org","size":83818,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":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":"8182f4bd04b930292221fda7148d4f4845f387d2","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-05-05T15:27:42Z","pushed_at":"2016-05-05T09:03:50Z","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":113434,"stargazers_count":11220,"watchers_count":11220,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6524,"mirror_url":null,"open_issues_count":1186,"forks":6524,"open_issues":1186,"watchers":11220,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6697"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/6697"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6697"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6697/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6697/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/6697/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/b4920fc3bd4f865ec045278caf71a1658c32d818"}}}}