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.

PCA with dataframe can't real explained_variance_ratio_ except nan

See original GitHub issue

What 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
TomAugspurgercommented, Jul 27, 2020

DataFrame.to_dask_array(lengths=True) will give you a Dask Array with known partition lengths, at the cost of computing them.

0reactions
TomAugspurgercommented, Sep 25, 2020

Thanks for following up.

Read more comments on GitHub >

github_iconTop 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 >

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