@@ -98,28 +98,6 @@ def __init__(
98
98
.. warning::
99
99
100
100
The implementation currently does not support sparse matrices.
101
-
102
- Examples
103
- --------
104
- >>> from dask_ml.decomposition import TruncatedSVD
105
- >>> import dask.array as da
106
- >>> X = da.random.normal(size=(1000, 20), chunks=(100, 20))
107
- >>> svd = TruncatedSVD(n_components=5, n_iter=3, random_state=42)
108
- >>> svd.fit(X) # doctest: +NORMALIZE_WHITESPACE
109
- TruncatedSVD(algorithm='tsqr', n_components=5, n_iter=3,
110
- random_state=42, tol=0.0)
111
-
112
- >>> print(svd.explained_variance_ratio_) # doctest: +ELLIPSIS
113
- [0.06386323 0.06176776 0.05901293 0.0576399 0.05726607]
114
- >>> print(svd.explained_variance_ratio_.sum()) # doctest: +ELLIPSIS
115
- 0.299...
116
- >>> print(svd.singular_values_) # doctest: +ELLIPSIS
117
- array([35.92469517, 35.32922121, 34.53368856, 34.138..., 34.013...])
118
-
119
- Note that ``transform`` returns a ``dask.Array``.
120
-
121
- >>> svd.transform(X)
122
- dask.array<sum-agg, shape=(1000, 5), dtype=float64, chunksize=(100, 5)>
123
101
"""
124
102
self .algorithm = algorithm
125
103
self .n_components = n_components
@@ -148,7 +126,7 @@ def fit(self, X, y=None):
148
126
149
127
def _check_array (self , X ):
150
128
if self .n_components >= X .shape [1 ]:
151
- raise ValueError (
129
+ raise ValueError ( # pragma: no cover
152
130
"n_components must be < n_features; "
153
131
"got {} >= {}" .format (self .n_components , X .shape [1 ])
154
132
)
@@ -174,14 +152,14 @@ def fit_transform(self, X, y=None):
174
152
"""
175
153
X = self ._check_array (X )
176
154
if self .algorithm not in {"tsqr" , "randomized" }:
177
- raise ValueError (
155
+ raise ValueError ( # pragma: no cover
178
156
"`algorithm` must be 'tsqr' or 'randomized', not '{}'" .format (
179
157
self .algorithm
180
158
)
181
159
)
182
160
if self .algorithm == "tsqr" :
183
161
if has_keyword (da .linalg .svd , "full_matrices" ):
184
- u , s , v = da .linalg .svd (X , full_matrices = False )
162
+ u , s , v = da .linalg .svd (X , full_matrices = False ) # pragma: no cover
185
163
else :
186
164
u , s , v = da .linalg .svd (X )
187
165
u = u [:, : self .n_components ]
@@ -245,4 +223,4 @@ def inverse_transform(self, X):
245
223
Note that this is always a dense array.
246
224
"""
247
225
# X = check_array(X)
248
- return X @ self .components_
226
+ return X @ self .components_ # pragma: no cover
0 commit comments