code: def test_permutation_importance_equivalence_array_dataframe(
      n_jobs, max_samples
  ):
      # This test checks that the column shuffling logic has the same behavior
      # both a dataframe and a simple numpy array.
      pd = pytest.importorskip("pandas")
  
      # regression test to make sure that sequential and parallel calls will
      # output the same results.
      X, y = make_regression(
          n_samples=100, n_features=5, random_state=0
      )
      X_df = pd.DataFrame(X)
  
      # Add a categorical feature that is statistically linked to y:
      binner = KBinsDiscretizer(n_bins=3, encode="ordinal")
      cat_column = binner.fit_transform(y.reshape(-1, 1))
  
      # Concatenate the extra column to the numpy array: integers will be
      # cast to float values
      X = np.hstack([X, cat_column])
      assert X.dtype.kind == "f"
  
      # Insert extra column as a non-numpy-native dtype (while keeping backward
      # compat for old pandas versions):
      if hasattr(pd, "Categorical"):
          cat_column = pd.Categorical(cat_column.ravel())
      else:
          cat_column = cat_column.ravel()
      new_col_idx = len(X_df.columns)
      X_df[new_col_idx] = cat_column
      assert X_df[new_col_idx].dtype == cat_column.dtype
  
      # Stich an arbitrary index to the dataframe:
      X_df.index = np.arange(len(X_df)).astype(str)
  
      rf = RandomForestRegressor(
          n_estimators=5, max_depth=3, random_state=0
      )
      rf.fit(X, y)
  
      n_repeats = 3
      importance_array = permutation_importance(
          rf,
          X,
          y,
          n_repeats=n_repeats,
          random_state=0,
          n_jobs=n_jobs,
          max_samples=max_samples,
      )
  
      # First check that the problem is structured enough and that the model is
      # complex enough to not yield trivial, constant importances:
      imp_min = importance_array["importances"].min()
      imp_max = importance_array["importances"].max()
      assert imp_max - imp_min > 0.3
  
      # Now check that importances computed on dataframe matche the values
      # of those computed on the array with the same data.
      importance_dataframe = permutation_importance(
          rf,
          X_df,
          y,
          n_repeats=n_repeats,
          random_state=0,
          n_jobs=n_jobs,
          max_samples=max_samples,
      )
      assert_allclose(
          importance_array["importances"],
          importance_dataframe["importances"],
      )
  
imports: import numpy
  import pytest
  from numpy.testing import assert_allclose
  from sklearn.compose import ColumnTransformer
  from sklearn.datasets import load_diabetes, load_iris, make_classification, make_regression
  from sklearn.dummy import DummyClassifier
  from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
  from sklearn.impute import SimpleImputer
  from sklearn.inspection import permutation_importance
  from sklearn.linear_model import LinearRegression, LogisticRegression
  from sklearn.metrics import get_scorer, mean_squared_error, r2_score
  from sklearn.model_selection import train_test_split
  from sklearn.pipeline import make_pipeline
  from sklearn.preprocessing import KBinsDiscretizer, OneHotEncoder, StandardScaler, scale
  from sklearn.utils import parallel_backend
  from sklearn.utils._testing import _convert_container
label_desc: Use image node_id 8 for calling a global function with example usage: test_permutation_importance_equivalence_array_dataframe(n_jobs, max_samples) without return types