@@ -12,12 +12,11 @@ def collect_dataset() -> tuple[ndarray, ndarray]:
1212 Returns:
1313 tuple[ndarray, ndarray]: Feature matrix and target labels.
1414
15- Example:
16- >>> features, targets = collect_dataset()
17- >>> features.shape
18- (150, 4)
19- >>> targets.shape
20- (150,)
15+ >>> features, targets = collect_dataset()
16+ >>> features.shape
17+ (150, 4)
18+ >>> targets.shape
19+ (150,)
2120 """
2221 iris_dataset = load_iris ()
2322 return np .array (iris_dataset .data ), np .array (iris_dataset .target )
@@ -34,11 +33,10 @@ def compute_pairwise_affinities(data_matrix: ndarray, sigma: float = 1.0) -> nda
3433 Returns:
3534 ndarray: Symmetrized probability matrix.
3635
37- Example:
38- >>> x = np.array([[0.0, 0.0], [1.0, 0.0]])
39- >>> probabilities = compute_pairwise_affinities(x)
40- >>> float(round(probabilities[0, 1], 3))
41- 0.25
36+ >>> x = np.array([[0.0, 0.0], [1.0, 0.0]])
37+ >>> probabilities = compute_pairwise_affinities(x)
38+ >>> float(round(probabilities[0, 1], 3))
39+ 0.25
4240 """
4341 n_samples = data_matrix .shape [0 ]
4442 squared_sum = np .sum (np .square (data_matrix ), axis = 1 )
@@ -63,11 +61,10 @@ def compute_low_dim_affinities(embedding_matrix: ndarray) -> tuple[ndarray, ndar
6361 Returns:
6462 tuple[ndarray, ndarray]: (Q probability matrix, numerator matrix).
6563
66- Example:
67- >>> y = np.array([[0.0, 0.0], [1.0, 0.0]])
68- >>> q_matrix, numerators = compute_low_dim_affinities(y)
69- >>> q_matrix.shape
70- (2, 2)
64+ >>> y = np.array([[0.0, 0.0], [1.0, 0.0]])
65+ >>> q_matrix, numerators = compute_low_dim_affinities(y)
66+ >>> q_matrix.shape
67+ (2, 2)
7168 """
7269 squared_sum = np .sum (np .square (embedding_matrix ), axis = 1 )
7370 numerator_matrix = 1 / (
@@ -101,11 +98,10 @@ def apply_tsne(
10198 Returns:
10299 ndarray: Low-dimensional embedding of the data.
103100
104- Example:
105- >>> features, _ = collect_dataset()
106- >>> embedding = apply_tsne(features, n_components=2, n_iter=50)
107- >>> embedding.shape
108- (150, 2)
101+ >>> features, _ = collect_dataset()
102+ >>> embedding = apply_tsne(features, n_components=2, n_iter=50)
103+ >>> embedding.shape
104+ (150, 2)
109105 """
110106 if n_components < 1 or n_iter < 1 :
111107 raise ValueError ("n_components and n_iter must be >= 1" )
@@ -147,10 +143,9 @@ def main() -> None:
147143 """
148144 Run t-SNE on the Iris dataset and display the first 5 embeddings.
149145
150- Example:
151- >>> main() # doctest: +ELLIPSIS
152- t-SNE embedding (first 5 points):
153- [[...
146+ >>> main() # doctest: +ELLIPSIS
147+ t-SNE embedding (first 5 points):
148+ [[...
154149 """
155150 features , _labels = collect_dataset ()
156151 embedding = apply_tsne (features , n_components = 2 , n_iter = 300 )
0 commit comments