{"action":"created","comment":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/74234217","id":74234217,"diff_hunk":"@@ -15,31 +16,43 @@\n def test_silhouette():\n     # Tests the Silhouette Coefficient.\n     dataset = datasets.load_iris()\n-    X = dataset.data\n+    X_dense = dataset.data\n+    X_csr = csr_matrix(X_dense)\n+    X_dok = sp.dok_matrix(X_dense)\n+    X_lil = sp.lil_matrix(X_dense)\n     y = dataset.target\n-    D = pairwise_distances(X, metric='euclidean')\n-    # Given that the actual labels are used, we can assume that S would be\n-    # positive.\n-    silhouette = silhouette_score(D, y, metric='precomputed')\n-    assert(silhouette > 0)\n-    # Test without calculating D\n-    silhouette_metric = silhouette_score(X, y, metric='euclidean')\n-    assert_almost_equal(silhouette, silhouette_metric)\n-    # Test with sampling\n-    silhouette = silhouette_score(D, y, metric='precomputed',\n-                                  sample_size=int(X.shape[0] / 2),\n-                                  random_state=0)\n-    silhouette_metric = silhouette_score(X, y, metric='euclidean',\n-                                         sample_size=int(X.shape[0] / 2),\n-                                         random_state=0)\n-    assert(silhouette > 0)\n-    assert(silhouette_metric > 0)\n-    assert_almost_equal(silhouette_metric, silhouette)\n-    # Test with sparse X\n-    X_sparse = csr_matrix(X)\n-    D = pairwise_distances(X_sparse, metric='euclidean')\n-    silhouette = silhouette_score(D, y, metric='precomputed')\n-    assert(silhouette > 0)\n+\n+    for X in [X_dense, X_csr, X_dok, X_lil]:\n+        D = pairwise_distances(X, metric='euclidean')\n+        # Given that the actual labels are used, we can assume that S would be\n+        # positive.\n+        score_precomputed = silhouette_score(D, y, metric='precomputed')\n+        assert(score_precomputed > 0)\n+        # Test without calculating D\n+        score_euclidean = silhouette_score(X, y, metric='euclidean')\n+        assert_almost_equal(score_precomputed, score_euclidean)\n+\n+        if X is X_dense:\n+            score_dense_without_sampling = score_precomputed\n+        else:\n+            assert_almost_equal(score_euclidean,\n+                                score_dense_without_sampling)\n+\n+        # Test with sampling\n+        score_precomputed = silhouette_score(D, y, metric='precomputed',\n+                                             sample_size=int(X.shape[0] / 2),\n+                                             random_state=0)\n+        score_euclidean = silhouette_score(X, y, metric='euclidean',\n+                                           sample_size=int(X.shape[0] / 2),\n+                                           random_state=0)\n+        assert(score_precomputed > 0)\n+        assert(score_euclidean > 0)","path":"sklearn/metrics/cluster/tests/test_unsupervised.py","position":null,"original_position":64,"commit_id":"9240c7cd1d1acfba34c55bb01b29263e101f45a1","original_commit_id":"3a42817e63631b4417099dacfe8f61f674c8ecd1","user":{"login":"yenchenlin","id":7057863,"avatar_url":"https://avatars.githubusercontent.com/u/7057863?v=3","gravatar_id":"","url":"https://api.github.com/users/yenchenlin","html_url":"https://github.com/yenchenlin","followers_url":"https://api.github.com/users/yenchenlin/followers","following_url":"https://api.github.com/users/yenchenlin/following{/other_user}","gists_url":"https://api.github.com/users/yenchenlin/gists{/gist_id}","starred_url":"https://api.github.com/users/yenchenlin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yenchenlin/subscriptions","organizations_url":"https://api.github.com/users/yenchenlin/orgs","repos_url":"https://api.github.com/users/yenchenlin/repos","events_url":"https://api.github.com/users/yenchenlin/events{/privacy}","received_events_url":"https://api.github.com/users/yenchenlin/received_events","type":"User","site_admin":false},"body":"Let's use it!","created_at":"2016-08-10T12:29:36Z","updated_at":"2016-08-10T12:29:36Z","html_url":"https://github.com/scikit-learn/scikit-learn/pull/7170#discussion_r74234217","pull_request_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7170","_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/comments/74234217"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/7170#discussion_r74234217"},"pull_request":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7170"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7170","id":80738493,"html_url":"https://github.com/scikit-learn/scikit-learn/pull/7170","diff_url":"https://github.com/scikit-learn/scikit-learn/pull/7170.diff","patch_url":"https://github.com/scikit-learn/scikit-learn/pull/7170.patch","issue_url":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7170","number":7170,"state":"open","locked":false,"title":"[MRG+1] Make Silhouette_score support sparse X","user":{"login":"yenchenlin","id":7057863,"avatar_url":"https://avatars.githubusercontent.com/u/7057863?v=3","gravatar_id":"","url":"https://api.github.com/users/yenchenlin","html_url":"https://github.com/yenchenlin","followers_url":"https://api.github.com/users/yenchenlin/followers","following_url":"https://api.github.com/users/yenchenlin/following{/other_user}","gists_url":"https://api.github.com/users/yenchenlin/gists{/gist_id}","starred_url":"https://api.github.com/users/yenchenlin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yenchenlin/subscriptions","organizations_url":"https://api.github.com/users/yenchenlin/orgs","repos_url":"https://api.github.com/users/yenchenlin/repos","events_url":"https://api.github.com/users/yenchenlin/events{/privacy}","received_events_url":"https://api.github.com/users/yenchenlin/received_events","type":"User","site_admin":false},"body":"Currently `silhouette_score` only support dense data, this PR would make it support sparse input.\r\nAlso, this PR fix #6317.","created_at":"2016-08-10T05:58:27Z","updated_at":"2016-08-10T12:29:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"100990a7af881ff5688a424480e8d79a6c267537","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7170/commits","review_comments_url":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7170/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/7170/comments","statuses_url":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/9240c7cd1d1acfba34c55bb01b29263e101f45a1","head":{"label":"yenchenlin:silhouette-score","ref":"silhouette-score","sha":"9240c7cd1d1acfba34c55bb01b29263e101f45a1","user":{"login":"yenchenlin","id":7057863,"avatar_url":"https://avatars.githubusercontent.com/u/7057863?v=3","gravatar_id":"","url":"https://api.github.com/users/yenchenlin","html_url":"https://github.com/yenchenlin","followers_url":"https://api.github.com/users/yenchenlin/followers","following_url":"https://api.github.com/users/yenchenlin/following{/other_user}","gists_url":"https://api.github.com/users/yenchenlin/gists{/gist_id}","starred_url":"https://api.github.com/users/yenchenlin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yenchenlin/subscriptions","organizations_url":"https://api.github.com/users/yenchenlin/orgs","repos_url":"https://api.github.com/users/yenchenlin/repos","events_url":"https://api.github.com/users/yenchenlin/events{/privacy}","received_events_url":"https://api.github.com/users/yenchenlin/received_events","type":"User","site_admin":false},"repo":{"id":50281797,"name":"scikit-learn","full_name":"yenchenlin/scikit-learn","owner":{"login":"yenchenlin","id":7057863,"avatar_url":"https://avatars.githubusercontent.com/u/7057863?v=3","gravatar_id":"","url":"https://api.github.com/users/yenchenlin","html_url":"https://github.com/yenchenlin","followers_url":"https://api.github.com/users/yenchenlin/followers","following_url":"https://api.github.com/users/yenchenlin/following{/other_user}","gists_url":"https://api.github.com/users/yenchenlin/gists{/gist_id}","starred_url":"https://api.github.com/users/yenchenlin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yenchenlin/subscriptions","organizations_url":"https://api.github.com/users/yenchenlin/orgs","repos_url":"https://api.github.com/users/yenchenlin/repos","events_url":"https://api.github.com/users/yenchenlin/events{/privacy}","received_events_url":"https://api.github.com/users/yenchenlin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yenchenlin/scikit-learn","description":"scikit-learn: machine learning in Python","fork":true,"url":"https://api.github.com/repos/yenchenlin/scikit-learn","forks_url":"https://api.github.com/repos/yenchenlin/scikit-learn/forks","keys_url":"https://api.github.com/repos/yenchenlin/scikit-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yenchenlin/scikit-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yenchenlin/scikit-learn/teams","hooks_url":"https://api.github.com/repos/yenchenlin/scikit-learn/hooks","issue_events_url":"https://api.github.com/repos/yenchenlin/scikit-learn/issues/events{/number}","events_url":"https://api.github.com/repos/yenchenlin/scikit-learn/events","assignees_url":"https://api.github.com/repos/yenchenlin/scikit-learn/assignees{/user}","branches_url":"https://api.github.com/repos/yenchenlin/scikit-learn/branches{/branch}","tags_url":"https://api.github.com/repos/yenchenlin/scikit-learn/tags","blobs_url":"https://api.github.com/repos/yenchenlin/scikit-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yenchenlin/scikit-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yenchenlin/scikit-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/yenchenlin/scikit-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yenchenlin/scikit-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/yenchenlin/scikit-learn/languages","stargazers_url":"https://api.github.com/repos/yenchenlin/scikit-learn/stargazers","contributors_url":"https://api.github.com/repos/yenchenlin/scikit-learn/contributors","subscribers_url":"https://api.github.com/repos/yenchenlin/scikit-learn/subscribers","subscription_url":"https://api.github.com/repos/yenchenlin/scikit-learn/subscription","commits_url":"https://api.github.com/repos/yenchenlin/scikit-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/yenchenlin/scikit-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/yenchenlin/scikit-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/yenchenlin/scikit-learn/issues/comments{/number}","contents_url":"https://api.github.com/repos/yenchenlin/scikit-learn/contents/{+path}","compare_url":"https://api.github.com/repos/yenchenlin/scikit-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yenchenlin/scikit-learn/merges","archive_url":"https://api.github.com/repos/yenchenlin/scikit-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yenchenlin/scikit-learn/downloads","issues_url":"https://api.github.com/repos/yenchenlin/scikit-learn/issues{/number}","pulls_url":"https://api.github.com/repos/yenchenlin/scikit-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/yenchenlin/scikit-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/yenchenlin/scikit-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yenchenlin/scikit-learn/labels{/name}","releases_url":"https://api.github.com/repos/yenchenlin/scikit-learn/releases{/id}","deployments_url":"https://api.github.com/repos/yenchenlin/scikit-learn/deployments","created_at":"2016-01-24T10:01:07Z","updated_at":"2016-01-24T10:01:14Z","pushed_at":"2016-08-10T12:29:18Z","git_url":"git://github.com/yenchenlin/scikit-learn.git","ssh_url":"git@github.com:yenchenlin/scikit-learn.git","clone_url":"https://github.com/yenchenlin/scikit-learn.git","svn_url":"https://github.com/yenchenlin/scikit-learn","homepage":"http://scikit-learn.org","size":72642,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":0,"forks":2,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scikit-learn:master","ref":"master","sha":"1f8eaacef157acea876ad9369239010da554e69f","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-10T12:00:58Z","pushed_at":"2016-08-10T12:29:21Z","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":121291,"stargazers_count":12767,"watchers_count":12767,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7391,"mirror_url":null,"open_issues_count":1258,"forks":7391,"open_issues":1258,"watchers":12767,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7170"},"html":{"href":"https://github.com/scikit-learn/scikit-learn/pull/7170"},"issue":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7170"},"comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/issues/7170/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/pulls/7170/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/7170/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-learn/scikit-learn/statuses/9240c7cd1d1acfba34c55bb01b29263e101f45a1"}}}}
{"actor":{"display_login":"yenchenlin"}}