code: def test_whitening():
      # Check that PCA output has unit-variance
      rng = np.random.RandomState(0)
      n_samples = 100
      n_features = 80
      n_components = 30
      rank = 50
  
      # some low rank data with correlated features
      X = np.dot(
          rng.randn(n_samples, rank),
          np.dot(
              np.diag(np.linspace(10.0, 1.0, rank)),
              rng.randn(rank, n_features),
          ),
      )
      # the component-wise variance of the first 50 features is 3 times the
      # mean component-wise variance of the remaining 30 features
      X[:, :50] *= 3
  
      assert X.shape == (n_samples, n_features)
  
      # the component-wise variance is thus highly varying:
      assert X.std(axis=0).std() > 43.8
      dX = da.from_array(X, chunks=(50, n_features))
  
      for solver, copy in product(solver_list, (True, False)):
          # whiten the data while projecting to the lower dim subspace
          X_ = (
              dX.copy()
          )  # make sure we keep an original across iterations.
          pca = dd.PCA(
              n_components=n_components,
              whiten=True,
              copy=copy,
              svd_solver=solver,
              random_state=0,
              iterated_power=4,
          )
          # test fit_transform
          X_whitened = pca.fit_transform(X_.copy())
          assert X_whitened.shape == (n_samples, n_components)
          # X_whitened2 = pca.transform(X_)
          # XXX: These differ for randomized.
          # assert_eq(X_whitened.compute(), X_whitened2.compute(),
          #           atol=tol, rtol=tol)
  
          assert_almost_equal(
              X_whitened.std(ddof=1, axis=0),
              np.ones(n_components),
              decimal=6,
          )
          assert_almost_equal(
              X_whitened.mean(axis=0), np.zeros(n_components)
          )
  
          X_ = dX.copy()
          pca = dd.PCA(
              n_components=n_components,
              whiten=False,
              copy=copy,
              svd_solver=solver,
              random_state=0,
          ).fit(X_)
          X_unwhitened = pca.transform(X_)
          assert X_unwhitened.shape == (n_samples, n_components)
  
          # in that case the output components still have varying variances
          assert_almost_equal(X_unwhitened.std(axis=0).std(), 74.1, 1)
  
imports: from itertools import product
  import dask.array
  import dask.dataframe
  import numpy
  import pandas
  import pytest
  import scipy
  import sklearn.decomposition
  from dask.array.utils import assert_eq
  from numpy.testing import assert_almost_equal, assert_array_almost_equal, assert_raises
  from sklearn import datasets
  from sklearn.utils import check_random_state
  import dask_ml.decomposition
  from dask_ml._compat import DASK_2_26_0
  from dask_ml.utils import assert_estimator_equal, flip_vector_signs, svd_flip
label_desc: Use image node_id 5 for calling a global function with example usage: test_whitening() without return types