{"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/54719514","id":54719514,"diff_hunk":"@@ -1089,10 +1096,24 @@ def _iter_indices(self, X, y, labels=None):\n                              (n_test, n_classes))\n \n         rng = check_random_state(self.random_state)\n+        # p_i = fraction of classes in dataset\n         p_i = class_counts / float(n_samples)\n-        n_i = np.round(n_train * p_i).astype(int)\n+        # n_i = number of samples per class in training set\n+        n_i = np.floor(n_train * p_i).astype(int)\n+        # n_i = number of samples per class in test set","path":"sklearn/model_selection/_split.py","position":39,"original_position":39,"commit_id":"da032ecde34d6978a25759424e6a7b348ea132ad","original_commit_id":"da032ecde34d6978a25759424e6a7b348ea132ad","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":"(Minor nitpick) `n_i` --> `t_i`","created_at":"2016-03-02T13:07:19Z","updated_at":"2016-03-02T13:07:19Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/6472#discussion_r54719514","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6472","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/54719514"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/6472#discussion_r54719514"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6472"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6472","id":61309538,"html_url":"https://github.com/scikit-learn/scikit-learn/pull/6472","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/6472.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/6472.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6472","number":6472,"state":"open","locked":false,"title":"fix sampling in stratified shuffle split, break tests that test sampling","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":"Fixes #6471.\r\nThis breaks some tests for stratified shuffle split. From my understanding, it actually now has the correct statistics, and the tests are wrong.\r\n\r\nI'll remove the asserts etc if we can agree on this implementation (and how the tests need to be changed).\r\n\r\nThis tries to adjust ``t_i`` and ``n_i`` before the sampling happens, and makes sure ``sum(t_i) == n_test`` and ``sum(n_i) == n_train``.\r\n\r\nAlso, it adds in the \"missing\" samples based on their class frequency. So on expectation, this should be doing exactly the right thing (I think, I didn't have any coffee today yet).\r\n\r\nThe ugly bit is\r\n```python\r\nnp.bincount(rng.permutation(np.repeat(range(n_classes), left_over_per_class))[:missing_train], minlength=n_classes)\r\n```\r\nwhich is the only way I new to say \"sample ``missing_train`` many points from the classes in ``left_over_per_class``\". I feel there should be a better way to say that.\r\n\r\nThe first test that breaks checks that if something with ``class_counts = [4, 3, 5]`` is split into 8 training and test points, the class probabilities in training and test set are the same.\r\nWith the given random state, it is split into ``[2, 1, 1]`` and ``[2, 2, 4]``, which I think is fine, the test disagrees.\r\n\r\n","created_at":"2016-03-01T21:15:46Z","updated_at":"2016-03-02T13:07:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fa12922b33aee50ace7edc71979492173aef58e3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6472/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6472/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/6472/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/da032ecde34d6978a25759424e6a7b348ea132ad","head":{"label":"amueller:stratified_shuffle_split_simplify","ref":"stratified_shuffle_split_simplify","sha":"da032ecde34d6978a25759424e6a7b348ea132ad","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},"repo":{"id":1622872,"name":"scikit-learn","full_name":"amueller/scikit-learn","owner":{"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},"private":false,"html_url":"https://github.com/amueller/scikit-learn","description":"scikit-learn main repo","fork":true,"url":"https://api.github.com/repos/amueller/scikit-learn","forks_url":"https://api.github.com/repos/amueller/scikit-learn/forks","keys_url":"https://api.github.com/repos/amueller/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amueller/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amueller/scikit-learn/teams","hooks_url":"https://api.github.com/repos/amueller/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/amueller/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/amueller/scikit-learn/events","assignees_url":"https://api.github.com/repos/amueller/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/amueller/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/amueller/scikit-learn/tags","blobs_url":"https://api.github.com/repos/amueller/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amueller/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amueller/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/amueller/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amueller/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/amueller/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/amueller/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/amueller/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/amueller/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/amueller/scikit-learn/subscription","commits_url":"https://api.github.com/repos/amueller/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/amueller/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/amueller/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/amueller/scikit-learn/issues/comments{/number}","contents_url":"https://api.github.com/repos/amueller/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/amueller/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amueller/scikit-learn/merges","archive_url":"https://api.github.com/repos/amueller/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amueller/scikit-learn/downloads","issues_url":"https://api.github.com/repos/amueller/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/amueller/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/amueller/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/amueller/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amueller/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/amueller/scikit-learn/releases{/id}","deployments_url":"https://api.github.com/repos/amueller/scikit-learn/deployments","created_at":"2011-04-16T12:41:21Z","updated_at":"2015-04-30T15:05:11Z","pushed_at":"2016-03-01T23:07:12Z","git_url":"git://github.com/amueller/scikit-learn.git","ssh_url":"git@github.com:amueller/scikit-learn.git","clone_url":"https://github.com/amueller/scikit-learn.git","svn_url":"https://github.com/amueller/scikit-learn","homepage":"http://scikit-learn.sourceforge.net","size":68010,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":0,"forks":5,"open_issues":0,"watchers":6,"default_branch":"master"}},"base":{"label":"scikit-learn:master","ref":"master","sha":"d3d8490ca63e644b3f8e7e376a9a4a95ad58ff45","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-03-02T13:00:23Z","pushed_at":"2016-03-02T10:02:10Z","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":101159,"stargazers_count":9976,"watchers_count":9976,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5845,"mirror_url":null,"open_issues_count":1091,"forks":5845,"open_issues":1091,"watchers":9976,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6472"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/6472"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6472"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6472/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6472/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/6472/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/da032ecde34d6978a25759424e6a7b348ea132ad"}}}}