From f38231e4c9cb43b8b49d789c21d2376def039c9c Mon Sep 17 00:00:00 2001 From: Jake Vanderplas Date: Fri, 3 Mar 2017 04:32:03 -0800 Subject: [PATCH] [MRG+1] BUG: fix svd_solver validation in PCA.fit (#8496) * BUG: fix svd_solver validation in PCA.fit * TST: add test of pca svd_solver --- sklearn/decomposition/pca.py | 3 +++ sklearn/decomposition/tests/test_pca.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/sklearn/decomposition/pca.py b/sklearn/decomposition/pca.py index a3abaa6217df8..f7cb01a422645 100644 --- a/sklearn/decomposition/pca.py +++ b/sklearn/decomposition/pca.py @@ -386,6 +386,9 @@ def _fit(self, X): return self._fit_full(X, n_components) elif svd_solver in ['arpack', 'randomized']: return self._fit_truncated(X, n_components, svd_solver) + else: + raise ValueError("Unrecognized svd_solver='{0}'" + "".format(svd_solver)) def _fit_full(self, X, n_components): """Fit the model by computing full SVD on X""" diff --git a/sklearn/decomposition/tests/test_pca.py b/sklearn/decomposition/tests/test_pca.py index 5a9bcb756cbe4..ea321089d719c 100644 --- a/sklearn/decomposition/tests/test_pca.py +++ b/sklearn/decomposition/tests/test_pca.py @@ -584,3 +584,9 @@ def test_pca_spase_input(): pca = PCA(n_components=3, svd_solver=svd_solver) assert_raises(TypeError, pca.fit, X) + + +def test_pca_bad_solver(): + X = np.random.RandomState(0).rand(5, 4) + pca = PCA(n_components=3, svd_solver='bad_argument') + assert_raises(ValueError, pca.fit, X)