{"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/74374431","id":74374431,"diff_hunk":"@@ -63,6 +64,83 @@ def test_input_estimator_unchanged():\n     assert_true(transformer.estimator is est)\n \n \n+def check_invalid_max_n_features(est, X, y):\n+    max_n_features = X.shape[1]\n+    for invalid_max_n_feature in [-1, max_n_features+1, 'gobbledigook']:\n+        transformer = SelectFromModel(estimator=est,\n+                                      max_n_features=invalid_max_n_feature)\n+        assert_raises(ValueError, transformer.fit, X, y)\n+\n+\n+def check_valid_max_n_features(est, X, y):\n+    max_n_features = X.shape[1]\n+    for valid_max_n_feature in [0, max_n_features, 'all', 5]:\n+        transformer = SelectFromModel(estimator=est,\n+                                      max_n_features=valid_max_n_feature)\n+        transformer.fit(X, y)\n+        X_new = transformer.transform(X)\n+        if valid_max_n_feature == 'all':\n+            valid_max_n_feature = max_n_features\n+        assert_equal(X_new.shape[1], valid_max_n_feature)\n+\n+\n+def check_max_n_features(est, X, y):\n+    max_n_features = X.shape[1]\n+\n+    check_valid_max_n_features(est, X, y)\n+    check_invalid_max_n_features(est, X, y)\n+\n+    transformer1 = SelectFromModel(estimator=est, max_n_features='all')\n+    transformer2 = SelectFromModel(estimator=est,\n+                                   max_n_features=max_n_features)\n+    transformer1.fit(X, y)\n+    transformer2.fit(X, y)\n+    X_new1, X_new2 = transformer1.transform(X), transformer2.transform(X)\n+    assert_array_equal(X_new1, X_new2)\n+\n+    \"\"\"\n+    Test max_n_features against actual model.\n+    \"\"\"\n+    transformer1 = SelectFromModel(estimator=Lasso(alpha=0.025))\n+    transformer1.fit(X, y)\n+    X_new1 = transformer1.transform(X)\n+    for n_features in range(1, X_new1.shape[1]+1):\n+        transformer2 = SelectFromModel(estimator=Lasso(alpha=0.025),\n+                                       max_n_features=n_features)\n+        transformer2.fit(X, y)\n+        X_new2 = transformer2.transform(X)\n+        assert_array_equal(X_new1[:, :n_features], X_new2)\n+\n+    \"\"\"\n+    Test if max_n_features can break tie among feature importance\n+    \"\"\"\n+    for n_features in range(max_n_features):\n+        transformer = SelectFromModel(est, max_n_features=n_features)\n+        X[:, n_features] = 1","path":"sklearn/feature_selection/tests/test_from_model.py","position":null,"original_position":64,"commit_id":"21e487b148effcd5c17ac0623cae4b5266e6bf30","original_commit_id":"ad0a8b3bc1adb0c0975558977e729d3faefafdee","user":{"login":"jnothman","id":78827,"avatar_url":"https://avatars.githubusercontent.com/u/78827?v=3","gravatar_id":"","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":"```python\r\nclass FixedImportanceClassifier(BaseEstimator):\r\n    def __init__(self, importances):\r\n        self.importances = importances\r\n    def fit(self, X, y=None):\r\n        self.feature_importances_ = self.importances\r\n```\r\nmight work...?","created_at":"2016-08-11T06:44:30Z","updated_at":"2016-08-11T06:44:30Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/6717#discussion_r74374431","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6717","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/74374431"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/6717#discussion_r74374431"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6717"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6717","id":67831427,"html_url":"https://github.com/scikit-learn/scikit-learn/pull/6717","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/6717.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/6717.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6717","number":6717,"state":"open","locked":false,"title":"[MRG] Implementing SelectKBest feature in SelectFromModel","user":{"login":"qmaruf","id":530250,"avatar_url":"https://avatars.githubusercontent.com/u/530250?v=3","gravatar_id":"","url":"https://api.github.com/users/qmaruf","html_url":"https://github.com/qmaruf","followers_url":"https://api.github.com/users/qmaruf/followers","following_url":"https://api.github.com/users/qmaruf/following{/other_user}","gists_url":"https://api.github.com/users/qmaruf/gists{/gist_id}","starred_url":"https://api.github.com/users/qmaruf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qmaruf/subscriptions","organizations_url":"https://api.github.com/users/qmaruf/orgs","repos_url":"https://api.github.com/users/qmaruf/repos","events_url":"https://api.github.com/users/qmaruf/events{/privacy}","received_events_url":"https://api.github.com/users/qmaruf/received_events","type":"User","site_admin":false},"body":"Working on #6689 to implement `SelectKBest` feature in `SelectFromModel`.\r\nIt should return top `k` most important features.","created_at":"2016-04-26T06:08:24Z","updated_at":"2016-08-11T06:44:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"82a525e63391a75aef2efedb8a4b119c00afba62","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6717/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6717/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/6717/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/21e487b148effcd5c17ac0623cae4b5266e6bf30","head":{"label":"qmaruf:add-selectKbest-feature-for-models","ref":"add-selectKbest-feature-for-models","sha":"21e487b148effcd5c17ac0623cae4b5266e6bf30","user":{"login":"qmaruf","id":530250,"avatar_url":"https://avatars.githubusercontent.com/u/530250?v=3","gravatar_id":"","url":"https://api.github.com/users/qmaruf","html_url":"https://github.com/qmaruf","followers_url":"https://api.github.com/users/qmaruf/followers","following_url":"https://api.github.com/users/qmaruf/following{/other_user}","gists_url":"https://api.github.com/users/qmaruf/gists{/gist_id}","starred_url":"https://api.github.com/users/qmaruf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qmaruf/subscriptions","organizations_url":"https://api.github.com/users/qmaruf/orgs","repos_url":"https://api.github.com/users/qmaruf/repos","events_url":"https://api.github.com/users/qmaruf/events{/privacy}","received_events_url":"https://api.github.com/users/qmaruf/received_events","type":"User","site_admin":false},"repo":{"id":54616351,"name":"scikit-learn","full_name":"qmaruf/scikit-learn","owner":{"login":"qmaruf","id":530250,"avatar_url":"https://avatars.githubusercontent.com/u/530250?v=3","gravatar_id":"","url":"https://api.github.com/users/qmaruf","html_url":"https://github.com/qmaruf","followers_url":"https://api.github.com/users/qmaruf/followers","following_url":"https://api.github.com/users/qmaruf/following{/other_user}","gists_url":"https://api.github.com/users/qmaruf/gists{/gist_id}","starred_url":"https://api.github.com/users/qmaruf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qmaruf/subscriptions","organizations_url":"https://api.github.com/users/qmaruf/orgs","repos_url":"https://api.github.com/users/qmaruf/repos","events_url":"https://api.github.com/users/qmaruf/events{/privacy}","received_events_url":"https://api.github.com/users/qmaruf/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/qmaruf/scikit-learn","description":"scikit-learn: machine learning in Python","fork":true,"url":"https://api.github.com/repos/qmaruf/scikit-learn","forks_url":"https://api.github.com/repos/qmaruf/scikit-learn/forks","keys_url":"https://api.github.com/repos/qmaruf/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/qmaruf/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/qmaruf/scikit-learn/teams","hooks_url":"https://api.github.com/repos/qmaruf/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/qmaruf/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/qmaruf/scikit-learn/events","assignees_url":"https://api.github.com/repos/qmaruf/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/qmaruf/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/qmaruf/scikit-learn/tags","blobs_url":"https://api.github.com/repos/qmaruf/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/qmaruf/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/qmaruf/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/qmaruf/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/qmaruf/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/qmaruf/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/qmaruf/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/qmaruf/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/qmaruf/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/qmaruf/scikit-learn/subscription","commits_url":"https://api.github.com/repos/qmaruf/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/qmaruf/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/qmaruf/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/qmaruf/scikit-learn/issues/comments{/number}","contents_url":"https://api.github.com/repos/qmaruf/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/qmaruf/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/qmaruf/scikit-learn/merges","archive_url":"https://api.github.com/repos/qmaruf/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/qmaruf/scikit-learn/downloads","issues_url":"https://api.github.com/repos/qmaruf/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/qmaruf/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/qmaruf/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/qmaruf/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/qmaruf/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/qmaruf/scikit-learn/releases{/id}","deployments_url":"https://api.github.com/repos/qmaruf/scikit-learn/deployments","created_at":"2016-03-24T05:13:37Z","updated_at":"2016-03-24T05:13:44Z","pushed_at":"2016-08-10T18:37:48Z","git_url":"git://github.com/qmaruf/scikit-learn.git","ssh_url":"git@github.com:qmaruf/scikit-learn.git","clone_url":"https://github.com/qmaruf/scikit-learn.git","svn_url":"https://github.com/qmaruf/scikit-learn","homepage":"http://scikit-learn.org","size":72043,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"427179b2136d23f47b8cb15cd8b9ee609b8cb097","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-08-11T05:33:40Z","pushed_at":"2016-08-11T00:41:46Z","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":121247,"stargazers_count":12777,"watchers_count":12777,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7398,"mirror_url":null,"open_issues_count":1260,"forks":7398,"open_issues":1260,"watchers":12777,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6717"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/6717"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6717"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/6717/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/6717/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/6717/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/21e487b148effcd5c17ac0623cae4b5266e6bf30"}}}}
{"actor":{"display_login":"jnothman"}}