code: def test_infer_dim_by_explained_variance(setup):
      X = iris
      pca = PCA(n_components=0.95, svd_solver="full")
      pca.fit(X)
      assert pca.n_components == 0.95
      assert pca.n_components_ == 2
  
      pca = PCA(n_components=0.01, svd_solver="full")
      pca.fit(X)
      assert pca.n_components == 0.01
      assert pca.n_components_ == 1
  
      rng = np.random.RandomState(0)
      # more features than samples
      X = mt.tensor(rng.rand(5, 20))
      pca = PCA(n_components=0.5, svd_solver="full").fit(X)
      assert pca.n_components == 0.5
      assert pca.n_components_ == 2
  
imports: from itertools import product
  import numpy
  import pytest
  import scipy
  from sklearn import datasets
  from sklearn.utils._testing import assert_array_almost_equal, assert_almost_equal, assert_raises_regex, assert_raise_message, assert_raises
  from ....None import tensor
  from .._pca import PCA, _assess_dimension, _infer_dimension
label_desc: Use image node_id 18 for calling a global function with example usage: test_infer_dim_by_explained_variance(setup) without return types