Skip to content

Commit e4980bc

Browse files
committed
Merge pull request scikit-learn#1470 from kuantkid/fix_spectral_cluster_test
FIX spectral clustering test error in OSX and ADD spectral embedding to sphere examples
2 parents d9138f4 + b07608e commit e4980bc

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

examples/manifold/plot_manifold_sphere.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,19 @@
124124
ax.yaxis.set_major_formatter(NullFormatter())
125125
pl.axis('tight')
126126

127+
# Perform Spectral Embedding.
128+
t0 = time()
129+
se = manifold.SpectralEmbedding(n_components=2,
130+
n_neighbors=n_neighbors)
131+
trans_data = se.fit_transform(sphere_data).T
132+
t1 = time()
133+
print "Spectral Embedding: %.2g sec" % (t1 - t0)
134+
135+
ax = fig.add_subplot(248)
136+
pl.scatter(trans_data[0], trans_data[1], c=colors, cmap=pl.cm.rainbow)
137+
pl.title("Spectral Embedding (%.2g sec)" % (t1 - t0))
138+
ax.xaxis.set_major_formatter(NullFormatter())
139+
ax.yaxis.set_major_formatter(NullFormatter())
140+
pl.axis('tight')
141+
127142
pl.show()

sklearn/cluster/tests/test_spectral.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818

1919

2020
def test_spectral_clustering():
21-
S = np.array([[1, 5, 2, 1, 0, 0, 0],
22-
[5, 1, 3, 1, 0, 0, 0],
23-
[2, 3, 1, 1, 0, 0, 0],
24-
[1, 1, 1, 1, 2, 1, 1],
25-
[0, 0, 0, 2, 2, 3, 2],
26-
[0, 0, 0, 1, 3, 1, 4],
27-
[0, 0, 0, 1, 2, 4, 1],
28-
])
21+
S = np.array([[1.0, 1.0, 1.0, 0.2, 0.0, 0.0, 0.0],
22+
[1.0, 1.0, 1.0, 0.2, 0.0, 0.0, 0.0],
23+
[1.0, 1.0, 1.0, 0.2, 0.0, 0.0, 0.0],
24+
[0.2, 0.2, 0.2, 1.0, 1.0, 1.0, 1.0],
25+
[0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0],
26+
[0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0],
27+
[0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0]])
2928

3029
for eigen_solver in ('arpack', 'lobpcg'):
3130
for assign_labels in ('kmeans', 'discretize'):
@@ -155,7 +154,7 @@ def test_spectral_clustering_sparse():
155154

156155

157156
def test_affinities():
158-
X, y = make_blobs(n_samples=40, random_state=1, centers=[[1, 1], [-1, -1]],
157+
X, y = make_blobs(n_samples=40, random_state=2, centers=[[1, 1], [-1, -1]],
159158
cluster_std=0.4)
160159
# nearest neighbors affinity
161160
sp = SpectralClustering(n_clusters=2, affinity='nearest_neighbors',

0 commit comments

Comments
 (0)