{"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/40417382","id":40417382,"diff_hunk":"@@ -0,0 +1,147 @@\n+\n+\"\"\"\n+Testing for Isolation Forest algorithm (sklearn.ensemble.iforest).\n+\"\"\"\n+\n+# Authors: Nicolas Goix <nicolas.goix@telecom-paristech.fr>\n+#          Alexandre Gramfort <alexandre.gramfort@telecom-paristech.fr>\n+# License: BSD 3 clause\n+\n+import numpy as np\n+\n+from sklearn.utils.testing import assert_array_equal\n+from sklearn.utils.testing import assert_array_almost_equal\n+from sklearn.utils.testing import assert_raises\n+from sklearn.utils.testing import assert_warns\n+from sklearn.utils.testing import assert_equal\n+from sklearn.utils.testing import assert_true\n+from sklearn.utils.testing import ignore_warnings\n+\n+from sklearn.grid_search import GridSearchCV, ParameterGrid\n+from sklearn.ensemble import IsolationForest\n+from sklearn.cross_validation import train_test_split\n+from sklearn.datasets import load_boston, load_iris\n+from sklearn.utils import check_random_state\n+\n+from scipy.sparse import csc_matrix, csr_matrix\n+\n+rng = check_random_state(0)\n+\n+# load the iris dataset\n+# and randomly permute it\n+iris = load_iris()\n+perm = rng.permutation(iris.target.size)\n+iris.data = iris.data[perm]\n+iris.target = iris.target[perm]\n+\n+# also load the boston dataset\n+# and randomly permute it\n+boston = load_boston()\n+perm = rng.permutation(boston.target.size)\n+boston.data = boston.data[perm]\n+boston.target = boston.target[perm]\n+\n+\n+def test_iforest():\n+    \"\"\"Check Isolation Forest for various parameter settings.\"\"\"\n+    X_train = np.array([[0, 1], [1, 2]])\n+    X_test = np.array([[2, 1], [1, 1]])\n+\n+    grid = ParameterGrid({\"n_estimators\": [3],\n+                          \"max_samples\": [0.5, 1.0, 3],\n+                          \"bootstrap\": [True, False]})\n+\n+    with ignore_warnings():\n+        for params in grid:\n+            IsolationForest(random_state=rng,\n+                            **params).fit(X_train).predict(X_test)\n+\n+\n+def test_iforest_sparse():\n+    \"\"\"Check IForest for various parameter settings on sparse input.\"\"\"\n+    rng = check_random_state(0)\n+    X_train, X_test, y_train, y_test = train_test_split(boston.data[:50],\n+                                                        boston.target[:50],\n+                                                        random_state=rng)\n+    grid = ParameterGrid({\"max_samples\": [0.5, 1.0],\n+                          \"bootstrap\": [True, False]})\n+\n+    for sparse_format in [csc_matrix, csr_matrix]:\n+        X_train_sparse = sparse_format(X_train)\n+        X_test_sparse = sparse_format(X_test)\n+\n+        for params in grid:\n+            # Trained on sparse format\n+            sparse_classifier = IsolationForest(\n+                random_state=1,\n+                **params\n+            ).fit(X_train_sparse)\n+            sparse_results = sparse_classifier.predict(X_test_sparse)\n+\n+            # Trained on dense format\n+            dense_results = IsolationForest(\n+                random_state=1,\n+                **params\n+            ).fit(X_train).predict(X_test)\n+\n+            assert_array_equal(sparse_results, dense_results)\n+            assert_array_equal(sparse_results, dense_results)\n+\n+\n+def test_iforest_error():\n+    \"\"\"Test that it gives proper exception on deficient input.\"\"\"\n+    X = iris.data\n+\n+    # Test max_samples\n+    assert_raises(ValueError,\n+                  IsolationForest(max_samples=-1).fit, X)\n+    assert_raises(ValueError,\n+                  IsolationForest(max_samples=0.0).fit, X)\n+    assert_raises(ValueError,\n+                  IsolationForest(max_samples=2.0).fit, X)\n+    assert_warns(UserWarning,\n+                 IsolationForest(max_samples=1000).fit, X)\n+    # cannot check for string values\n+\n+\n+def test_iforest_parallel_regression():\n+    \"\"\"Check parallel regression.\"\"\"\n+    rng = check_random_state(0)\n+\n+    X_train, X_test, y_train, y_test = train_test_split(boston.data,\n+                                                        boston.target,\n+                                                        random_state=rng)\n+\n+    ensemble = IsolationForest(n_jobs=3,\n+                               random_state=0).fit(X_train)\n+\n+    ensemble.set_params(n_jobs=1)\n+    y1 = ensemble.predict(X_test)\n+    ensemble.set_params(n_jobs=2)\n+    y2 = ensemble.predict(X_test)\n+    assert_array_almost_equal(y1, y2)\n+\n+    ensemble = IsolationForest(n_jobs=1,\n+                               random_state=0).fit(X_train)\n+\n+    y3 = ensemble.predict(X_test)\n+    assert_array_almost_equal(y1, y3)\n+\n+\n+def test_iforest_gridsearch():","path":"sklearn/ensemble/tests/test_iforest.py","position":131,"original_position":131,"commit_id":"6b0603cd3c4cfef05173da3f1f8f58916f3b432f","original_commit_id":"6b0603cd3c4cfef05173da3f1f8f58916f3b432f","user":{"login":"glouppe","id":477771,"avatar_url":"https://avatars.githubusercontent.com/u/477771?v=3","gravatar_id":"","url":"https://api.github.com/users/glouppe","html_url":"https://github.com/glouppe","followers_url":"https://api.github.com/users/glouppe/followers","following_url":"https://api.github.com/users/glouppe/following{/other_user}","gists_url":"https://api.github.com/users/glouppe/gists{/gist_id}","starred_url":"https://api.github.com/users/glouppe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glouppe/subscriptions","organizations_url":"https://api.github.com/users/glouppe/orgs","repos_url":"https://api.github.com/users/glouppe/repos","events_url":"https://api.github.com/users/glouppe/events{/privacy}","received_events_url":"https://api.github.com/users/glouppe/received_events","type":"User","site_admin":false},"body":"Isn't this kind of tests now part of the common tests? @amueller ","created_at":"2015-09-25T10:31:40Z","updated_at":"2015-09-25T10:31:40Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/4163#discussion_r40417382","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4163","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/40417382"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/4163#discussion_r40417382"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4163"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4163","id":28045812,"html_url":"https://github.com/scikit-learn/scikit-learn/pull/4163","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/4163.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/4163.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/4163","number":4163,"state":"open","locked":false,"title":"MRG: Iforest - new anomaly detection algo","user":{"login":"ngoix","id":5682433,"avatar_url":"https://avatars.githubusercontent.com/u/5682433?v=3","gravatar_id":"","url":"https://api.github.com/users/ngoix","html_url":"https://github.com/ngoix","followers_url":"https://api.github.com/users/ngoix/followers","following_url":"https://api.github.com/users/ngoix/following{/other_user}","gists_url":"https://api.github.com/users/ngoix/gists{/gist_id}","starred_url":"https://api.github.com/users/ngoix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ngoix/subscriptions","organizations_url":"https://api.github.com/users/ngoix/orgs","repos_url":"https://api.github.com/users/ngoix/repos","events_url":"https://api.github.com/users/ngoix/events{/privacy}","received_events_url":"https://api.github.com/users/ngoix/received_events","type":"User","site_admin":false},"body":"Isolation Forest (iForest) algorithm\r\nBased on previous discussion \r\nhttp://sourceforge.net/p/scikit-learn/mailman/message/32485020\r\n","created_at":"2015-01-26T17:49:56Z","updated_at":"2015-09-25T10:31:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0a6117db5b71862c8108e055507a6b6d975e0188","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4163/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4163/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/4163/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/6b0603cd3c4cfef05173da3f1f8f58916f3b432f","head":{"label":"ngoix:iforest","ref":"iforest","sha":"6b0603cd3c4cfef05173da3f1f8f58916f3b432f","user":{"login":"ngoix","id":5682433,"avatar_url":"https://avatars.githubusercontent.com/u/5682433?v=3","gravatar_id":"","url":"https://api.github.com/users/ngoix","html_url":"https://github.com/ngoix","followers_url":"https://api.github.com/users/ngoix/followers","following_url":"https://api.github.com/users/ngoix/following{/other_user}","gists_url":"https://api.github.com/users/ngoix/gists{/gist_id}","starred_url":"https://api.github.com/users/ngoix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ngoix/subscriptions","organizations_url":"https://api.github.com/users/ngoix/orgs","repos_url":"https://api.github.com/users/ngoix/repos","events_url":"https://api.github.com/users/ngoix/events{/privacy}","received_events_url":"https://api.github.com/users/ngoix/received_events","type":"User","site_admin":false},"repo":{"id":20621109,"name":"scikit-learn","full_name":"ngoix/scikit-learn","owner":{"login":"ngoix","id":5682433,"avatar_url":"https://avatars.githubusercontent.com/u/5682433?v=3","gravatar_id":"","url":"https://api.github.com/users/ngoix","html_url":"https://github.com/ngoix","followers_url":"https://api.github.com/users/ngoix/followers","following_url":"https://api.github.com/users/ngoix/following{/other_user}","gists_url":"https://api.github.com/users/ngoix/gists{/gist_id}","starred_url":"https://api.github.com/users/ngoix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ngoix/subscriptions","organizations_url":"https://api.github.com/users/ngoix/orgs","repos_url":"https://api.github.com/users/ngoix/repos","events_url":"https://api.github.com/users/ngoix/events{/privacy}","received_events_url":"https://api.github.com/users/ngoix/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ngoix/scikit-learn","description":"scikit-learn: machine learning in Python","fork":true,"url":"https://api.github.com/repos/ngoix/scikit-learn","forks_url":"https://api.github.com/repos/ngoix/scikit-learn/forks","keys_url":"https://api.github.com/repos/ngoix/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ngoix/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ngoix/scikit-learn/teams","hooks_url":"https://api.github.com/repos/ngoix/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/ngoix/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/ngoix/scikit-learn/events","assignees_url":"https://api.github.com/repos/ngoix/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/ngoix/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/ngoix/scikit-learn/tags","blobs_url":"https://api.github.com/repos/ngoix/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ngoix/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ngoix/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/ngoix/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ngoix/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/ngoix/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/ngoix/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/ngoix/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/ngoix/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/ngoix/scikit-learn/subscription","commits_url":"https://api.github.com/repos/ngoix/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/ngoix/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/ngoix/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/ngoix/scikit-learn/issues/comments{/number}","contents_url":"https://api.github.com/repos/ngoix/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/ngoix/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ngoix/scikit-learn/merges","archive_url":"https://api.github.com/repos/ngoix/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ngoix/scikit-learn/downloads","issues_url":"https://api.github.com/repos/ngoix/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/ngoix/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/ngoix/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/ngoix/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ngoix/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/ngoix/scikit-learn/releases{/id}","created_at":"2014-06-08T16:42:05Z","updated_at":"2015-08-24T12:34:34Z","pushed_at":"2015-09-23T18:53:32Z","git_url":"git://github.com/ngoix/scikit-learn.git","ssh_url":"git@github.com:ngoix/scikit-learn.git","clone_url":"https://github.com/ngoix/scikit-learn.git","svn_url":"https://github.com/ngoix/scikit-learn","homepage":"http://scikit-learn.org","size":66925,"stargazers_count":1,"watchers_count":1,"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":1,"default_branch":"master"}},"base":{"label":"scikit-learn:master","ref":"master","sha":"c82ad6d27c57438d3efe3c37e4bec110ecfe8e37","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-09-25T10:30:35Z","pushed_at":"2015-09-24T22:20:30Z","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":133866,"stargazers_count":7644,"watchers_count":7644,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4514,"mirror_url":null,"open_issues_count":749,"forks":4514,"open_issues":749,"watchers":7644,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4163"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/4163"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/4163"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/4163/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/4163/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/4163/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/6b0603cd3c4cfef05173da3f1f8f58916f3b432f"}}}}