MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / main

Function main

machine_learning/t_stochastic_neighbour_embedding.py:149–173  ·  view source on GitHub ↗

Run t-SNE on the Iris dataset and display the first 5 embeddings. >>> main() # doctest: +ELLIPSIS t-SNE embedding (first 5 points): [[...

()

Source from the content-addressed store, hash-verified

147
148
149def main() -> None:
150 """
151 Run t-SNE on the Iris dataset and display the first 5 embeddings.
152
153 >>> main() # doctest: +ELLIPSIS
154 t-SNE embedding (first 5 points):
155 [[...
156 """
157 features, _labels = collect_dataset()
158 embedding = apply_tsne(features, n_components=2, n_iter=300)
159
160 if not isinstance(embedding, np.ndarray):
161 raise TypeError("t-SNE embedding must be an ndarray")
162
163 print("t-SNE embedding (first 5 points):")
164 print(embedding[:5])
165
166 # Optional visualization (Ruff/mypy compliant)
167
168 # import matplotlib.pyplot as plt
169 # plt.scatter(embedding[:, 0], embedding[:, 1], c=labels, cmap="viridis")
170 # plt.title("t-SNE Visualization of the Iris Dataset")
171 # plt.xlabel("Dimension 1")
172 # plt.ylabel("Dimension 2")
173 # plt.show()
174
175
176if __name__ == "__main__":

Calls 2

apply_tsneFunction · 0.85
collect_datasetFunction · 0.70

Tested by

no test coverage detected