Skip to content

Commit

Permalink
constant number of eigenvalues (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt authored Jul 15, 2019
1 parent 87cfbf9 commit 0abf710
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/sources/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The CHANGELOG for the current development version is available at
##### Bug Fixes

- Fixed documentation of `iris_data()` under `iris.py` by adding a note about differences in the iris data in R and UCI machine learning repo.
- Make sure that if the `'svd'` mode is used in PCA, the number of eigenvalues is the same as when using `'eigen'` (append 0's zeros in that case) ([#565](https://github.com/rasbt/mlxtend/pull/565))

### Version 0.16.0 (05/12/2019)

Expand Down
4 changes: 4 additions & 0 deletions mlxtend/feature_extraction/principal_component_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ def _decomposition(self, mat, n_samples):
u, s, v = np.linalg.svd(mat_centered.T)
e_vecs, e_vals = u, s
e_vals = e_vals ** 2 / n_samples
if e_vals.shape[0] < e_vecs.shape[1]:
new_e_vals = np.zeros(e_vecs.shape[1])
new_e_vals[:e_vals.shape[0]] = e_vals
e_vals = new_e_vals

sort_idx = np.argsort(e_vals)[::-1]
e_vals, e_vecs = e_vals[sort_idx], e_vecs[:, sort_idx]
Expand Down

0 comments on commit 0abf710

Please sign in to comment.