8000 fix warning and behavior in randomized_svd wrt power iterations · scikit-learn/scikit-learn@5404197 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5404197

Browse files
committed
fix warning and behavior in randomized_svd wrt power iterations
1 parent db56cf4 commit 5404197

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

sklearn/utils/extmath.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from ..externals.six.moves import xrange
2626
from .sparsefuncs_fast import csr_row_norms
2727
from .validation import check_array
28-
from ..exceptions import NonBLASDotWarning
28+
from ..exceptions import NonBLASDotWarning, ChangedBehaviorWarning
2929

3030

3131
def norm(x):
@@ -351,24 +351,21 @@ def randomized_svd(M, n_components, n_oversamples=10, n_iter=None,
351351

352352
if n_iter is None:
353353
# Checks if the number of iterations is explicitely specified
354-
n_iter = 4
355-
n_iter_specified = False
356-
else:
357-
n_iter_specified = True
354+
# Adjust n_iter. 7 was found a good compromise for PCA. See #5299
355+
if n_components < .1 * min(M.shape) and n_iter < 7:
356+
n_iter = 7
357+
warnings.warn("The default number of power iterations is increased from 4"
358+
"to 7 in version 0.18 to achieve higher precision.",
359+
ChangedBehaviorWarning)
360+
else:
361+
n_iter = 4
358362

359363
if transpose == 'auto':
360364
transpose = n_samples < n_features
361365
if transpose:
362366
# this implementation is a bit faster with smaller shape[1]
363367
M = M.T
364368

365-
# Adjust n_iter. 7 was found a good compromise for PCA. See #5299
366-
if n_components < .1 * min(M.shape) and n_iter < 7:
367-
if n_iter_specified:
368-
warnings.warn("The number of power iterations is increased to "
369-
"7 to achieve higher precision.")
370-
n_iter = 7
371-
372369
Q = randomized_range_finder(M, n_random, n_iter,
373370
power_iteration_normalizer, random_state)
374371

0 commit comments

Comments
 (0)
0