class_docstr: Implementation of a simple black-box attribute inference attack.
  
  The idea is to train a simple neural network to learn the attacked feature from the rest of the features and the
  model's predictions. Assumes the availability of the attacked model's predictions for the samples under attack,
  in addition to the rest of the feature values. If this is not available, the true class label of the samples may be
  used as a proxy.
class_docstr_tok: ["Implementation","of","a","simple","black-box","attribute","inference","attack",".","The","idea","is","to","train","a","simple","neural","network","to","learn","the","attacked","feature","from","the","rest","of","the","features","and","the","model","'s","predictions",".","Assumes","the","availability","of","the","attacked","model","'s","predictions","for","the","samples","under","attack",",","in","addition","to","the","rest","of","the","feature","values",".","If","this","is","not","available",",","the","true","class","label","of","the","samples","may","be","used","as","a","proxy","."]
docstr: Infer the attacked feature.
  
  :param x: Input to attack. Includes all features except the attacked feature.
  :param y: True labels for x.
  :param pred: Original model's predictions for x.
  :type pred: `np.ndarray`
  :param values: Possible values for attacked feature. For a single column feature this should be a simple list
                 containing all possible values, in increasing order (the smallest value in the 0 index and so
                 on). For a multi-column feature (for example 1-hot encoded and then scaled), this should be a
                 list of lists, where each internal list represents a column (in increasing order) and the values
                 represent the possible values for that column (in increasing order). If not provided, is
                 computed from the training data when calling `fit`. Only relevant for categorical features.
  :type values: list, optional
  :return: The inferred feature values.
docstr_tok: ["Infer","the","attacked","feature",".",":","param","x",":","Input","to","attack",".","Includes","all","features","except","the","attacked","feature",".",":","param","y",":","True","labels","for","x.",":","param","pred",":","Original","model","'s","predictions","for","x.",":","type","pred",":","`","np.ndarray","`",":","param","values",":","Possible","values","for","attacked","feature",".","For","a","single","column","feature","this","should","be","a","simple","list","containing","all","possible","values",",","in","increasing","order","(","the","smallest","value","in","the","0","index","and","so","on",")",".","For","a","multi-column","feature","(","for","example","1-hot","encoded","and","then","scaled",")",",","this","should","be","a","list","of","lists",",","where","each","internal","list","represents","a","column","(","in","increasing","order",")","and","the","values","represent","the","possible","values","for","that","column","(","in","increasing","order",")",".","If","not","provided",",","is","computed","from","the","training","data","when","calling","`","fit","`",".","Only","relevant","for","categorical","features",".",":","type","values",":","list",",","optional",":","return",":","The","inferred","feature","values","."]
code: def infer(
      self, x: np.ndarray, y: Optional[np.ndarray] = None, **kwargs
  ) -> np.ndarray:
      """
      Infer the attacked feature.
  
      :param x: Input to attack. Includes all features except the attacked feature.
      :param y: True labels for x.
      :param pred: Original model's predictions for x.
      :type pred: `np.ndarray`
      :param values: Possible values for attacked feature. For a single column feature this should be a simple list
                     containing all possible values, in increasing order (the smallest value in the 0 index and so
                     on). For a multi-column feature (for example 1-hot encoded and then scaled), this should be a
                     list of lists, where each internal list represents a column (in increasing order) and the values
                     represent the possible values for that column (in increasing order). If not provided, is
                     computed from the training data when calling `fit`. Only relevant for categorical features.
      :type values: list, optional
      :return: The inferred feature values.
      """
      values: Optional[list] = kwargs.get("values")
  
      # if provided, override the values computed in fit()
      if values is not None:
          self._values = values
  
      pred: Optional[np.ndarray] = kwargs.get("pred")
  
      if pred is None:
          raise ValueError(
              "Please provide param `pred` of model predictions."
          )
  
      if pred.shape[0] != x.shape[0]:
          raise ValueError("Number of rows in x and y do not match")
      if self.estimator.input_shape is not None:
          if (
              isinstance(self.attack_feature, int)
              and self.estimator.input_shape[0] != x.shape[1] + 1
          ):
              raise ValueError(
                  "Number of features in x + 1 does not match input_shape of model"
              )
  
      x_test = x
      if self._encoder is not None:
          x_test = self._encoder.transform(x)
  
      if RegressorMixin in type(self.estimator).__mro__:
          if self.scale_range is not None:
              x_test = np.concatenate(
                  (
                      x_test,
                      minmax_scale(
                          pred, feature_range=self.scale_range
                      ),
                  ),
                  axis=1,
              ).astype(np.float32)
              if y is not None:
                  y = minmax_scale(y, feature_range=self.scale_range)
          else:
              x_test = np.concatenate(
                  (x_test, pred * self.prediction_normal_factor), axis=1
              ).astype(np.float32)
              if y is not None:
                  y = y * self.prediction_normal_factor
          if y is not None:
              y = y.reshape(-1, 1)
      else:
          x_test = np.concatenate((x_test, pred), axis=1).astype(
              np.float32
          )
          if y is not None:
              y = check_and_transform_label_format(
                  y,
                  nb_classes=self.estimator.nb_classes,
                  return_one_hot=True,
              )
  
      if y is not None:
          x_test = np.concatenate((x_test, y), axis=1)
  
      if self._attack_model_type == "nn":
          from torch.utils.data import DataLoader
          from art.utils import to_cuda, from_cuda
  
          self.attack_model.eval()  # type: ignore
          predictions: np.ndarray = np.array([])
          test_set = self._get_attack_dataset(feature=x_test)
          test_loader = DataLoader(
              test_set,
              batch_size=self.batch_size,
              shuffle=False,
              num_workers=0,
          )
          for input1, _ in test_loader:
              input1 = to_cuda(input1)
              outputs = self.attack_model(input1)  # type: ignore
              predicted = from_cuda(outputs)
  
              if np.size(predictions) == 0:
                  predictions = predicted.detach().numpy()
              else:
                  predictions = np.vstack(
                      (predictions, predicted.detach().numpy())
                  )
              if not self._is_continuous:
                  idx = np.argmax(predictions, axis=-1)
                  predictions = np.zeros(predictions.shape)
                  predictions[np.arange(predictions.shape[0]), idx] = 1
      elif self.attack_model is not None:
          predictions = self.attack_model.predict(x_test)
      if predictions is not None:
          predictions = predictions.astype(np.float32)
  
      if not self._is_continuous and self._values:
          if isinstance(self.attack_feature, int):
              if self._attack_model_type in ("gb", "lr", "svm"):
                  indexes = predictions
              else:
                  indexes = np.argmax(predictions, axis=1)
              predictions = np.array(
                  [self._values[int(index)] for index in indexes]
              )
          else:
              if self._attack_model_type in ("gb", "lr", "svm"):
                  predictions = check_and_transform_label_format(
                      predictions,
                      nb_classes=len(self._values),
                      return_one_hot=True,
                  )
              i = 0
              for column in predictions.T:
                  for index in range(len(self._values[i])):
                      np.place(
                          column,
                          [column == index],
                          self._values[i][index],
                      )
                  i += 1
      return np.array(predictions)
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import logging
  from typing import Optional, Union, Tuple, List, Any, TYPE_CHECKING
  import numpy
  from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
  from sklearn.ensemble import GradientBoostingClassifier, GradientBoostingRegressor
  from sklearn.linear_model import LogisticRegression, LinearRegression
  from sklearn.neighbors import KNeighborsClassifier, KNeighborsRegressor
  from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
  from sklearn.svm import SVC, SVR
  from sklearn.preprocessing import minmax_scale, OneHotEncoder, OrdinalEncoder
  from sklearn.compose import ColumnTransformer
  from art.estimators.estimator import BaseEstimator
  from art.estimators.classification.classifier import ClassifierMixin
  from art.attacks.attack import AttributeInferenceAttack
  from art.estimators.regression import RegressorMixin
  from art.utils import check_and_transform_label_format, float_to_categorical, floats_to_one_hot, get_feature_values, remove_attacked_feature
label_desc: Use image node_id 3 for calling the AttributeInferenceBlackBox obj's underlying member method code with example usage: obj.infer(x, y) and returns: np