From 33e0653e14d4c1903405c8c51f0dcaeff30cb288 Mon Sep 17 00:00:00 2001 From: dengemann Date: Wed, 4 Sep 2013 00:18:45 +0200 Subject: [PATCH] ENH: add check on init + appropriate test; COSMITS --- sklearn/decomposition/factor_analysis.py | 11 +++++++---- sklearn/decomposition/tests/test_factor_analysis.py | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sklearn/decomposition/factor_analysis.py b/sklearn/decomposition/factor_analysis.py index cadece7e432..fb4ecf046df 100644 --- a/sklearn/decomposition/factor_analysis.py +++ b/sklearn/decomposition/factor_analysis.py @@ -69,10 +69,10 @@ class FactorAnalysis(BaseEstimator, TransformerMixin): svd_method : {'svd', 'randomized'} Which SVD method to use. If 'svd' use standard SVD from scipy.linalg, - if 'randomized' use fast ``randomized`` function. Defaults to 'svd'. - For maximum precision you should choose 'svd'. For most applications - 'randomized' will be sufficiently precise while providing significant - speed gains. + if 'randomized' use fast ``randomized_svd`` function. Defaults to + 'randomized'. For maximum precision you should choose 'svd'. For most + applications 'randomized' will be sufficiently precise while providing + significant speed gains. random_state : int or RandomState Pseudo number generator state used for random sampling. Only used @@ -112,6 +112,9 @@ class FactorAnalysis(BaseEstimator, TransformerMixin): self.copy = copy self.tol = tol self.max_iter = max_iter + if svd_method not in ['svd', 'randomized']: + raise ValueError('SVD method %s is not supported. Please consider' + ' the documentation' % svd_method) self.svd_method = svd_method self.verbose = verbose self.noise_variance_init = noise_variance_init diff --git a/sklearn/decomposition/tests/test_factor_analysis.py b/sklearn/decomposition/tests/test_factor_analysis.py index 54505d8d066..e24a8864915 100644 --- a/sklearn/decomposition/tests/test_factor_analysis.py +++ b/sklearn/decomposition/tests/test_factor_analysis.py @@ -29,7 +29,10 @@ def test_factor_analysis(): # generate observations # wlog, mean is 0 X = np.dot(h, W) + noise - assert_raises(ValueError, FactorAnalysis(svd_method='foo').fit, X) + assert_raises(ValueError, FactorAnalysis, svd_method='foo') + fa_fail = FactorAnalysis() + fa_fail.svd_method = 'foo' + assert_raises(ValueError, fa_fail.fit, X) fas = [] for method in ['randomized', 'svd']: fa = FactorAnalysis(n_components=n_components, svd_method=method)