|
52 | 52 |
|
53 | 53 | # Create our sphere.
|
54 | 54 | random_state = check_random_state(0)
|
55 |
| -p = random_state.rand(n_samples)*(2*np.pi-0.55) |
56 |
| -t = random_state.rand(n_samples)*np.pi |
| 55 | +p = random_state.rand(n_samples) * (2 * np.pi - 0.55) |
| 56 | +t = random_state.rand(n_samples) * np.pi |
57 | 57 |
|
58 | 58 | # Sever the poles from the sphere.
|
59 |
| -indices = ((t < (np.pi-(np.pi/8))) & (t > ((np.pi/8)))) |
| 59 | +indices = ((t < (np.pi - (np.pi / 8))) & (t > ((np.pi / 8)))) |
60 | 60 | colors = p[indices]
|
61 |
| -x, y, z = np.sin(t[indices])*np.cos(p[indices]), \ |
62 |
| - np.sin(t[indices])*np.sin(p[indices]), \ |
| 61 | +x, y, z = np.sin(t[indices]) * np.cos(p[indices]), \ |
| 62 | + np.sin(t[indices]) * np.sin(p[indices]), \ |
63 | 63 | np.cos(t[indices])
|
64 | 64 |
|
65 | 65 | # Plot our dataset.
|
66 | 66 | fig = pl.figure(figsize=(15, 8))
|
67 | 67 | pl.suptitle("Manifold Learning with %i points, %i neighbors"
|
68 |
| - % (1000, n_neighbors), fontsize=14) |
| 68 | + % (1000, n_neighbors), fontsize=14) |
69 | 69 |
|
70 | 70 | ax = fig.add_subplot(241, projection='3d')
|
71 | 71 | ax.scatter(x, y, z, c=p[indices], cmap=pl.cm.rainbow)
|
|
83 | 83 |
|
84 | 84 | for i, method in enumerate(methods):
|
85 | 85 | t0 = time()
|
86 |
| - trans_data = manifold.LocallyLinearEmbedding(n_neighbors, 2, |
87 |
| - method=method).fit_transform(sphere_data).T |
| 86 | + trans_data = manifold\ |
| 87 | + .LocallyLinearEmbedding(n_neighbors, 2, |
| 88 | + method=method).fit_transform(sphere_data).T |
88 | 89 | t1 = time()
|
89 | 90 | print "%s: %.2g sec" % (methods[i], t1 - t0)
|
90 | 91 |
|
|
97 | 98 |
|
98 | 99 | # Perform Isomap Manifold learning.
|
99 | 100 | t0 = time()
|
100 |
| -trans_data = manifold.Isomap(n_neighbors, n_components=2).fit_transform(sphere_data).T |
| 101 | +trans_data = manifold.Isomap(n_neighbors, n_components=2)\ |
| 102 | + .fit_transform(sphere_data).T |
101 | 103 | t1 = time()
|
102 | 104 | print "%s: %.2g sec" % ('ISO', t1 - t0)
|
103 | 105 |
|
|
123 | 125 | pl.axis('tight')
|
124 | 126 |
|
125 | 127 | pl.show()
|
126 |
| - |
|
0 commit comments