code: def test_explained_variance(X_sparse, kind, n_components, solver):
      X = X_sparse if kind == "sparse" else X_sparse.toarray()
      svd = TruncatedSVD(n_components, algorithm=solver)
      X_tr = svd.fit_transform(X)
      # Assert that all the values are greater than 0
      assert_array_less(0.0, svd.explained_variance_ratio_)
  
      # Assert that total explained variance is less than 1
      assert_array_less(svd.explained_variance_ratio_.sum(), 1.0)
  
      # Test that explained_variance is correct
      total_variance = np.var(X_sparse.toarray(), axis=0).sum()
      variances = np.var(X_tr, axis=0)
      true_explained_variance_ratio = variances / total_variance
  
      assert_allclose(
          svd.explained_variance_ratio_,
          true_explained_variance_ratio,
      )
  
file_path: scikit-learn/sklearn/decomposition/tests/test_truncated_svd.py
imports: import numpy
  import pytest
  import scipy.sparse
  from sklearn.decomposition import PCA, TruncatedSVD
  from sklearn.utils import check_random_state
  from sklearn.utils._testing import assert_allclose, assert_array_less
label_desc: Use image node_id 8 for calling a global function with example usage: test_explained_variance(X_sparse, kind, n_components, solver) without return types