Skip to content

Commit b3f231e

Browse files
committed
Updated tsne.py
1 parent 850a805 commit b3f231e

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

machine_learning/tsne.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,33 +149,33 @@ def apply_tsne(
149149
return y
150150

151151

152-
def main() -> ndarray:
152+
def main() -> None:
153153
"""
154-
Run t-SNE on Iris dataset and return the embeddings.
155-
156-
Returns:
157-
ndarray: t-SNE embedding of the Iris dataset
154+
Run t-SNE on Iris dataset and display the first 5 embeddings.
158155
159156
Example:
160-
>>> result = main()
161-
>>> result.shape
162-
(150, 2)
163-
>>> isinstance(result, np.ndarray)
164-
True
157+
>>> main() # doctest: +ELLIPSIS
158+
t-SNE embedding (first 5 points):
159+
[[...
165160
"""
166161
data_x, _ = collect_dataset()
167162
y_emb = apply_tsne(data_x, n_components=2, n_iter=300)
168163

169164
if not isinstance(y_emb, np.ndarray):
170165
raise TypeError("t-SNE embedding must be an ndarray")
171166

172-
return y_emb
167+
print("t-SNE embedding (first 5 points):")
168+
print(y_emb[:5])
169+
170+
# Optional visualization (commented out for automated testing)
171+
# import matplotlib.pyplot as plt
172+
# plt.scatter(y_emb[:, 0], y_emb[:, 1], c=labels, cmap="viridis")
173+
# plt.title("t-SNE Visualization of Iris Dataset")
174+
# plt.xlabel("Dimension 1")
175+
# plt.ylabel("Dimension 2")
176+
# plt.show()
173177

174178

175179
if __name__ == "__main__":
176180
doctest.testmod()
177-
178-
# Demonstration of the algorithm
179-
result = main()
180-
print("t-SNE embedding (first 5 points):")
181-
print(result[:5])
181+
main()

0 commit comments

Comments
 (0)