question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

decomposition.PCA has no attribute 'singular_values_'

See original GitHub issue

Description

The singular_values_ attribute of PCA is broken.

Steps/Code to Reproduce

The docstring for PCA contains the following example:

import numpy as np
from sklearn.decomposition import PCA
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
pca = PCA(n_components=2)
pca.fit(X)
print(pca.singular_values_)

Expected Results

From the docstring:

[ 6.30061...  0.54980...]

Actual Results

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-340-afb570ab70cc> in <module>()
      4 pca = PCA(n_components=2)
      5 pca.fit(X)
----> 6 print(pca.singular_values_)

AttributeError: 'PCA' object has no attribute 'singular_values_'

Versions

Darwin-16.7.0-x86_64-i386-64bit
Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
NumPy 1.13.0
SciPy 0.19.1
Scikit-Learn 0.18.1

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rthcommented, Oct 18, 2017

The PCA.singular_values_ attribute was added in 0.19 (in https://github.com/scikit-learn/scikit-learn/pull/7685), it doesn’t exist in 0.18.1. Please update your scikit-learn version.

1reaction
harryscholescommented, Oct 18, 2017

My apologies! I didn’t realise I was out of date 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

sklearn.decomposition.PCA — scikit-learn 1.2.0 documentation
PCA : A demo of K-Means clustering on the handwritten digits data A demo of ... and then divided by the singular values...
Read more >
In sklearn.decomposition.PCA, why are components_ negative?
As you figured out in your answer, the results of a singular value decomposition (SVD) are not unique in terms of singular vectors....
Read more >
'PCA' object has no attribute 'explained_variance_'
Elbow Method - Finding the number of components required to preserve maximum variance. My code: pca = decomposition.PCA() vectorizer = ...
Read more >
8.5.1. sklearn.decomposition.PCA - GitHub Pages
This implementation uses the scipy.linalg implementation of the singular value decomposition. It only works for dense arrays and is not scalable to large ......
Read more >
dask_ml.decomposition.PCA - Dask-ML
Linear dimensionality reduction using Singular Value Decomposition of the data ... then divided by the singular values to ensure uncorrelated outputs with ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found