Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MRG+1] BUG: fix svd_solver validation in PCA.fit #8496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)