Skip to content

Commit

Permalink
[MRG+1] BUG: fix svd_solver validation in PCA.fit (scikit-learn#8496)
Browse files Browse the repository at this point in the history
* BUG: fix svd_solver validation in PCA.fit

* TST: add test of pca svd_solver
  • Loading branch information
jakevdp authored and TomDLT committed Mar 3, 2017
1 parent 1256bb7 commit f38231e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sklearn/decomposition/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
6 changes: 6 additions & 0 deletions sklearn/decomposition/tests/test_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit f38231e

Please sign in to comment.