code: def test_shadow_model_bb_attack_nonumeric(
      art_warning, get_iris_dataset
  ):
      try:
          (x_target, y_target), (x_shadow, y_shadow) = get_iris_dataset
  
          def transform_feature(x):
              x[x > 0.5] = 2.0
              x[(x > 0.2) & (x <= 0.5)] = 1.0
              x[x <= 0.2] = 0.0
              x[x == 2.0] = "A"
              x[x == 1.0] = "B"
              x[x == 0.0] = "C"
  
          feature = 1
          x_without_feature = np.delete(x_target, feature, 1)
          x_feature = (
              x_target[:, feature].copy().reshape(-1, 1).astype(object)
          )
          transform_feature(x_feature)
          # training data with feature (after transformation)
          x_target = np.concatenate(
              (x_without_feature[:, :feature], x_feature), axis=1
          )
          x_target = np.concatenate(
              (x_target, x_without_feature[:, feature:]), axis=1
          )
  
          x_shadow_without_feature = np.delete(x_shadow, feature, 1)
          x_shadow_feature = (
              x_shadow[:, feature].copy().reshape(-1, 1).astype(object)
          )
          transform_feature(x_shadow_feature)
          # shadow data with feature (after transformation)
          x_shadow = np.concatenate(
              (x_shadow_without_feature[:, :feature], x_shadow_feature),
              axis=1,
          )
          x_shadow = np.concatenate(
              (x_shadow, x_shadow_without_feature[:, feature:]), axis=1
          )
  
          target_train_size = len(x_target) // 2
          x_target_train = x_target[:target_train_size]
          y_target_train = y_target[:target_train_size]
          x_target_test = x_target[target_train_size:]
          y_target_test = y_target[target_train_size:]
  
          from sklearn.preprocessing import OneHotEncoder
          from sklearn.pipeline import Pipeline
  
          encoder = OneHotEncoder(handle_unknown="ignore")
          model = RandomForestClassifier()
          pipeline = Pipeline([("encoder", encoder), ("model", model)])
          pipeline.fit(
              x_target_train, np.argmax(y_target_train, axis=1)
          )
          art_classifier = ScikitlearnClassifier(
              pipeline, preprocessing=None
          )
  
          shadow_models = ShadowModels(
              art_classifier, num_shadow_models=1, random_state=7
          )
          shadow_dataset = shadow_models.generate_shadow_dataset(
              x_shadow, y_shadow
          )
          (mem_x, mem_y, mem_pred), (
              nonmem_x,
              nonmem_y,
              nonmem_pred,
          ) = shadow_dataset
  
          attack = MembershipInferenceBlackBox(
              art_classifier, attack_model_type="rf"
          )
          attack.fit(
              mem_x, mem_y, nonmem_x, nonmem_y, mem_pred, nonmem_pred
          )
  
          mem_infer = attack.infer(x_target_train, y_target_train)
          nonmem_infer = attack.infer(x_target_test, y_target_test)
          mem_acc = np.sum(mem_infer) / len(mem_infer)
          nonmem_acc = 1 - (np.sum(nonmem_infer) / len(nonmem_infer))
          accuracy = (
              mem_acc * len(mem_infer) + nonmem_acc * len(nonmem_infer)
          ) / (len(mem_infer) + len(nonmem_infer))
  
          assert accuracy == pytest.approx(0.7, abs=0.2)
      except ARTTestException as e:
          art_warning(e)
  
file_path: adversarial-robustness-toolbox/tests/attacks/inference/membership_inference/test_shadow_models.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  import numpy
  import pytest
  from sklearn.ensemble import RandomForestClassifier
  from art.attacks.inference.membership_inference.black_box import MembershipInferenceBlackBox
  from art.attacks.inference.membership_inference.shadow_models import ShadowModels
  from art.estimators.classification.scikitlearn import ScikitlearnRandomForestClassifier, ScikitlearnClassifier
  from art.utils import load_nursery, to_categorical
  from tests.utils import ARTTestException
label_desc: Use image node_id 2 for calling a global function with example usage: test_shadow_model_bb_attack_nonumeric(art_warning, get_iris_dataset) without return types