code: def test_explained_variance():
      # Check that PCA output has unit-variance
      rng = np.random.RandomState(0)
      n_samples = 100
      n_features = 80
  
      X = rng.randn(n_samples, n_features)
      dX = da.from_array(X, chunks=(50, n_features))
  
      pca = sd.PCA(n_components=2, svd_solver="full").fit(X)
      apca = dd.PCA(
          n_components=2, svd_solver="full", random_state=0
      ).fit(dX)
      assert_array_almost_equal(
          pca.explained_variance_, apca.explained_variance_, 1
      )
      assert_array_almost_equal(
          pca.explained_variance_ratio_,
          apca.explained_variance_ratio_,
          3,
      )
      assert_array_almost_equal(
          pca.noise_variance_, apca.noise_variance_, 3
      )
  
      rpca = dd.PCA(
          n_components=2,
          svd_solver="randomized",
          random_state=42,
          iterated_power=1,
      ).fit(dX)
      assert_array_almost_equal(
          pca.explained_variance_, rpca.explained_variance_, 1
      )
      assert_array_almost_equal(
          pca.explained_variance_ratio_,
          rpca.explained_variance_ratio_,
          1,
      )
      assert_array_almost_equal(
          pca.noise_variance_, rpca.noise_variance_, 1
      )
  
      # compare to empirical variances
      expected_result = np.linalg.eig(np.cov(X, rowvar=False))[0]
      expected_result = sorted(expected_result, reverse=True)[:2]
  
      X_pca = apca.transform(X)
      assert_array_almost_equal(
          apca.explained_variance_, np.var(X_pca, ddof=1, axis=0)
      )
      assert_array_almost_equal(
          apca.explained_variance_, expected_result
      )
  
      X_rpca = rpca.transform(X)
      assert_array_almost_equal(
          rpca.explained_variance_,
          np.var(X_rpca, ddof=1, axis=0),
          decimal=1,
      )
      assert_array_almost_equal(
          rpca.explained_variance_, expected_result, decimal=1
      )
  
      # Same with correlated data
      X = datasets.make_classification(
          n_samples,
          n_features,
          n_informative=n_features - 2,
          random_state=rng,
      )[0]
      dX = da.from_array(X, chunks=(50, n_features))
  
      pca = sd.PCA(n_components=2).fit(X)
      rpca = dd.PCA(
          n_components=2,
          svd_solver="randomized",
          random_state=rng,
          iterated_power=2,
      ).fit(dX)
      assert_array_almost_equal(
          pca.explained_variance_ratio_,
          rpca.explained_variance_ratio_,
          5,
      )
  
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 6 for calling a global function with example usage: test_explained_variance() without return types