PCA with dataframe can't real explained_variance_ratio_ except nan
See original GitHub issueWhat happened:
when use dask_ml.decomposition.PCA fit the dask.dataframe, then will get the nan of pca Attributes pca.explained_variance_ratio_/explained_variance_ ; maybe can’t get the dataframe shape lead to the error.
What you expected to happen: [0.99244289 0.00755711]
Minimal Complete Verifiable Example: [nan nan]
# Put your MCVE code here
import dask.dataframe as dd
import dask.array as da
import numpy as np
from dask_ml.decomposition import PCA
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
dX = da.from_array(X, chunks=X.shape)
pca = PCA(n_components=2)
pca.fit(dX)
print(pca.explained_variance_ratio_)
#the result is [0.99244289 0.00755711]
df = dd.from_dask_array(dX, columns=['a','b'])
pca = PCA(n_components=2, svd_solver='full')
pca.fit(df)
print(pca.explained_variance_ratio_)
#the result is [nan nan]
Anything else we need to know?:
Environment: python 3.6 dask 2.18.1 dask-glm 0.2.0 dask-ml 1.5.0 dask-xgboost 0.1.10
- Dask version:
- Python version:
- Operating System:
- Install method (conda, pip, source):
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:14 (8 by maintainers)
Top Results From Across the Web
how values corresponds to columns in PCA ... - Stack Overflow
PCA is invariant to permutation of the feature / variable (columns). The values that you get from pca.explained_variance_ratio_ is the ratio ...
Read more >sklearn.decomposition.PCA — scikit-learn 1.2.0 documentation
Principal component analysis (PCA). Linear dimensionality reduction using Singular Value Decomposition of the data to project it to a lower dimensional space. ...
Read more >Dimension Reduction with Principal Component Analysis (PCA)
Principal Component Analysis aka PCA performs dimension reduction in two steps: ... data.chas.replace( 0 , np.nan, inplace = True ) ...
Read more >sklearn.decomposition.PCA explained_variance_ratio_ ...
This is untested, but I believe the error is occurring because you're calling explained variance on the fit_transform object, as opposed to ...
Read more >Machine Learning: Step-By-Step - Towards Data Science
First, we load the data and create a dataframe. ... Using PCA, we can study the cumulative explained variance ratio of these features...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
DataFrame.to_dask_array(lengths=True)
will give you a Dask Array with known partition lengths, at the cost of computing them.Thanks for following up.