caliex commited on
Commit
b9cef6c
1 Parent(s): 353f6fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -8
app.py CHANGED
@@ -9,7 +9,8 @@ def compare_manifold_learning(methods, n_samples, n_neighbors, n_components, per
9
  S_points, S_color = datasets.make_s_curve(n_samples, random_state=0)
10
  transformed_data = []
11
 
12
- for method in methods:
 
13
  manifold_method = {
14
  "Locally Linear Embeddings Standard": manifold.LocallyLinearEmbedding(method="standard", n_neighbors=n_neighbors, n_components=n_components, eigen_solver="auto", random_state=0),
15
  "Locally Linear Embeddings LTSA": manifold.LocallyLinearEmbedding(method="ltsa", n_neighbors=n_neighbors, n_components=n_components, eigen_solver="auto", random_state=0),
@@ -22,17 +23,42 @@ def compare_manifold_learning(methods, n_samples, n_neighbors, n_components, per
22
  }[method]
23
  S_transformed = manifold_method.fit_transform(S_points)
24
  transformed_data.append(S_transformed)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  fig, axs = plt.subplots(1, len(transformed_data), figsize=(6 * len(transformed_data), 6))
27
  fig.suptitle("Manifold Learning Comparison", fontsize=16)
28
 
29
- for ax, method, data in zip(axs, methods, transformed_data):
 
 
 
30
  ax.scatter(data[:, 0], data[:, 1], c=S_color, cmap=plt.cm.Spectral)
31
  ax.set_title(f"Method: {method}")
32
  ax.axis("tight")
33
  ax.axis("off")
34
  ax.xaxis.set_major_locator(ticker.NullLocator())
35
  ax.yaxis.set_major_locator(ticker.NullLocator())
 
 
 
 
 
 
 
 
36
 
37
  plt.tight_layout()
38
  plt.savefig("plot.png")
@@ -41,14 +67,14 @@ def compare_manifold_learning(methods, n_samples, n_neighbors, n_components, per
41
  return "plot.png"
42
 
43
  method_options = [
44
- "Locally Linear Embeddings Standard",
45
- "Locally Linear Embeddings LTSA",
46
- "Locally Linear Embeddings Hessian",
47
- "Locally Linear Embeddings Modified",
48
  "Isomap",
49
- "MultiDimensional Scaling",
50
  "Spectral Embedding",
51
- "T-distributed Stochastic Neighbor Embedding"
52
  ]
53
 
54
  inputs = [
 
9
  S_points, S_color = datasets.make_s_curve(n_samples, random_state=0)
10
  transformed_data = []
11
 
12
+ if len(methods) == 1:
13
+ method = methods[0]
14
  manifold_method = {
15
  "Locally Linear Embeddings Standard": manifold.LocallyLinearEmbedding(method="standard", n_neighbors=n_neighbors, n_components=n_components, eigen_solver="auto", random_state=0),
16
  "Locally Linear Embeddings LTSA": manifold.LocallyLinearEmbedding(method="ltsa", n_neighbors=n_neighbors, n_components=n_components, eigen_solver="auto", random_state=0),
 
23
  }[method]
24
  S_transformed = manifold_method.fit_transform(S_points)
25
  transformed_data.append(S_transformed)
26
+ else:
27
+ for method in methods:
28
+ manifold_method = {
29
+ "Locally Linear Embeddings Standard": manifold.LocallyLinearEmbedding(method="standard", n_neighbors=n_neighbors, n_components=n_components, eigen_solver="auto", random_state=0),
30
+ "Locally Linear Embeddings LTSA": manifold.LocallyLinearEmbedding(method="ltsa", n_neighbors=n_neighbors, n_components=n_components, eigen_solver="auto", random_state=0),
31
+ "Locally Linear Embeddings Hessian": manifold.LocallyLinearEmbedding(method="hessian", n_neighbors=n_neighbors, n_components=n_components, eigen_solver="auto", random_state=0),
32
+ "Locally Linear Embeddings Modified": manifold.LocallyLinearEmbedding(method="modified", n_neighbors=n_neighbors, n_components=n_components, eigen_solver="auto", random_state=0),
33
+ "Isomap": manifold.Isomap(n_neighbors=n_neighbors, n_components=n_components, p=1),
34
+ "MultiDimensional Scaling": manifold.MDS(n_components=n_components, max_iter=50, n_init=4, random_state=0, normalized_stress=False),
35
+ "Spectral Embedding": manifold.SpectralEmbedding(n_components=n_components, n_neighbors=n_neighbors),
36
+ "T-distributed Stochastic Neighbor Embedding": manifold.TSNE(n_components=n_components, perplexity=perplexity, init="random", n_iter=250, random_state=0)
37
+ }[method]
38
+ S_transformed = manifold_method.fit_transform(S_points)
39
+ transformed_data.append(S_transformed)
40
 
41
  fig, axs = plt.subplots(1, len(transformed_data), figsize=(6 * len(transformed_data), 6))
42
  fig.suptitle("Manifold Learning Comparison", fontsize=16)
43
 
44
+ if len(methods) == 1:
45
+ ax = axs
46
+ method = methods[0]
47
+ data = transformed_data[0]
48
  ax.scatter(data[:, 0], data[:, 1], c=S_color, cmap=plt.cm.Spectral)
49
  ax.set_title(f"Method: {method}")
50
  ax.axis("tight")
51
  ax.axis("off")
52
  ax.xaxis.set_major_locator(ticker.NullLocator())
53
  ax.yaxis.set_major_locator(ticker.NullLocator())
54
+ else:
55
+ for ax, method, data in zip(axs, methods, transformed_data):
56
+ ax.scatter(data[:, 0], data[:, 1], c=S_color, cmap=plt.cm.Spectral)
57
+ ax.set_title(f"Method: {method}")
58
+ ax.axis("tight")
59
+ ax.axis("off")
60
+ ax.xaxis.set_major_locator(ticker.NullLocator())
61
+ ax.yaxis.set_major_locator(ticker.NullLocator())
62
 
63
  plt.tight_layout()
64
  plt.savefig("plot.png")
 
67
  return "plot.png"
68
 
69
  method_options = [
70
+ "LLE Standard",
71
+ "LLE LTSA",
72
+ "LLE Hessian",
73
+ "LLE Modified",
74
  "Isomap",
75
+ "MDS",
76
  "Spectral Embedding",
77
+ "t-SNE"
78
  ]
79
 
80
  inputs = [